/* ===== pfod Command for Hot Water ==== {.<+7>|A~<+5>Hot Water is `0~~OFF\ON} */ // Using and 19200 for send and receive, via Serial // GPRS shield V2 from SeeedStudio // This code uses Serial so remove shield when programming the mega // NOTE: Because of the RAM requirements, this code needs to be loaded onto a Arduino Mega 2560 or similar // It is NOT suitable for use on an Arduino UNO /* Code generated by pfodDesigner V1.2.542 * (c)2014-2015 Forward Computing and Control Pty. Ltd. * NSW Australia, www.forward.com.au * This generated code may be freely used for both private and commerical use */ #include #include "pfodSMS_SIM900.h" #include "pfodSecurity.h" pfodSMS_SIM900 pfodSMS; // create object to handle SMS messages pfodSecurity parser; // create parser to handle pfod messges // give the board pins names, if you change the pin number here you will change the pin controlled int cmd_A_pin = 3; // name the output pin for 'Hot Water is ' // the setup routine runs once on reset: void setup() { Serial.begin(19200); for (int i=3; i>0; i--) { // wait a few secs to see if we are being programmed delay(1000); } //pinMode(cmd_A_pin, INPUT_PULLUP); pinMode(cmd_A_pin, OUTPUT); // output for 'Hot Water is ' is initially LOW, uncomment line above if you want it initially HIGH // initialize the SMS and connect the parser pfodSMS.init(&Serial,9); // SeeedStudio GPRS shield V2 SKU: SLD01098P uses pin 9 for powerup/reset parser.connect(&pfodSMS); // connect parser to SMS stream // To set a password use next line instead, password uses 19 bytes of EEPROM starting from 0 // parser.connect(&pfodSMS, F("173057F7A706AF9BBE65D51122A14CEE")); // The password is upto 32 hex digits, 0..9 A..F // passwords shorter then 32 hex digits are padded with 0's // <<<<<<<<< Your extra setup code goes here } // the loop routine runs over and over again forever: void loop() { byte cmd = parser.parse(); // pass it to the parser // parser returns non-zero when a pfod command is fully parsed if (cmd != 0) { // have parsed a complete msg { to } byte* pfodFirstArg = parser.getFirstArg(); // may point to \0 if no arguments in this msg. long pfodLongRtn; // used for parsing long return arguments, if any if ('.' == cmd) { // pfodApp has connected and sent {.} , it is asking for the main menu // send back the menu designed sendMainMenu(); // now handle commands returned from button/sliders } else if('A'==cmd) { // user moved slider -- 'Hot Water is ' // set output based on slider 0 == LOW, 1 == HIGH parser.parseLong(pfodFirstArg,&pfodLongRtn); // parse first arg as a long digitalWrite(cmd_A_pin,pfodLongRtn); // set output sendMainMenuUpdate(); // always send back a pfod msg otherwise pfodApp will disconnect. } else if ('!' == cmd) { // CloseConnection command closeConnection(parser.getPfodAppStream()); } else { // unknown command parser.print(F("{}")); // always send back a pfod msg otherwise pfodApp will disconnect. } } // <<<<<<<<<<< Your other loop() code goes here } void closeConnection(Stream *io) { // nothing special here for SMS } void sendMainMenu() { parser.print(F("{.")); // start a Menu screen pfod message send_menuContents(); // send the menu contents parser.print(F("}")); // close pfod message } void sendMainMenuUpdate() { parser.print(F("{:")); // start an Update Menu pfod message send_menuContents(); // send the menu contents parser.print(F("}")); // close pfod message } // modify this method if you need to update the menu to reflect state changes void send_menuContents() { // send menu prompt parser.print(F("<+7>")); // send menu items parser.print(F("|A~<+5>Hot Water is\n`")); parser.print(digitalRead(cmd_A_pin)); // read current output state 0 Low or 1 High parser.print(F("~~OFF\\ON")); // Note the \\ inside the "'s to send \ // ============ end of menu item =========== } // ============= end generated code =========