/* ===== pfod Command for Menu_1 ==== pfodApp msg {.} --> {,<+4>~SMS Hot Water Control`0~V1|A<+4>`0~Hot Water is ~~Off\On~} */ // Using Mega2560 Serial1 and 19200 baud for send and receive to // Adafruit FONA 3G SIM5320 Cellular Breakout // This code allows Serial (USB) to be used for DEBUG // NOTE: Because of the RAM requirements, this code needs to be loaded onto a Arduino Mega 2560 or similar // NOTE: default baud rate for SIM5320 is 115200. This needs to changed to 19200 before use. /* Code generated by pfodDesignerV3 V3.0.3303 */ /* * (c)2014-2018 Forward Computing and Control Pty. Ltd. * NSW Australia, www.forward.com.au * This code is not warranted to be fit for any purpose. You may only use it at your own risk. * This generated code may be freely used for both private and commercial use * provide this copyright is maintained. */ #include // Download library from http://www.forward.com.au/pfod/pfodParserLibraries/index.html #include #include // add your pfod Password here for 128bit security // eg "b0Ux9akSiwKkwCtcnjTnpWp" but generate your own key, "" means no pfod password #define pfodSecurityCode "" // see https://www.forward.com.au/pfod/secureChallengeResponse/keyGenerator/index.html for a QR image key generator // and https://www.forward.com.au/pfod/secureChallengeResponse/index.html for more information int swap01(int); // method prototype for slider end swaps pfodSMS_SIM5320 pfodSMS; // create object to handle SMS messages pfodSecurity parser("V1"); // create a parser to handle the pfod messages // give the board pins names, if you change the pin number here you will change the pin controlled int cmd_A_var; // name the variable for 'Hot Water is' 0=Off 1=On const int cmd_A_pin = 8; // name the output D8 for 'Hot Water is' // the setup routine runs once on reset: void setup() { Serial1.begin(19200); for (int i=3; i>0; i--) { // wait a few secs delay(1000); } cmd_A_var = 0; //pinMode(cmd_A_pin, INPUT_PULLUP); pinMode(cmd_A_pin, OUTPUT); // output for 'Hot Water is' is initially LOW, //uncomment INPUT_PULLUP line above and set variable to 1, if you want it initially HIGH digitalWrite(cmd_A_pin,cmd_A_var); // set output // to set debugOut in pfodSMS_SIM5320 // Serial.begin(19200); // pfodSMS.setDebugStream(&Serial); // need to uncomment a #define DEBUG... in the pfodSMS_SIM5320.cpp file as well to get debug output // initialize the SMS and connect the parser pfodSMS.init(&Serial1); // just 4 pins used power and TX/RX parser.connect(&pfodSMS,F(pfodSecurityCode)); // connect parser to SMS stream // <<<<<<<<< Your extra setup code goes here } // the loop routine runs over and over again forever: void loop() { uint8_t cmd = parser.parse(); // parse incoming data from connection // parser returns non-zero when a pfod command is fully parsed if (cmd != 0) { // have parsed a complete msg { to } uint8_t* pfodFirstArg = parser.getFirstArg(); // may point to \0 if no arguments in this msg. pfod_MAYBE_UNUSED(pfodFirstArg); // may not be used, just suppress warning long pfodLongRtn; // used for parsing long return arguments, if any pfod_MAYBE_UNUSED(pfodLongRtn); // may not be used, just suppress warning if ('.' == cmd) { // pfodApp has connected and sent {.} , it is asking for the main menu if (!parser.isRefresh()) { sendMainMenu(); // send back the menu designed } else { sendMainMenuUpdate(); // menu is cached just send update } // now handle commands returned from button/sliders } else if('A'==cmd) { // user moved slider -- 'Hot Water is' // in the main Menu of Menu_1 // set output based on slider 0=Off 1=On parser.parseLong(pfodFirstArg,&pfodLongRtn); // parse first arg as a long cmd_A_var = (int)pfodLongRtn; // set variable digitalWrite(cmd_A_pin,cmd_A_var); // 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() { // !! Remember to change the parser version string // every time you edit this method parser.print(F("{,")); // start a Menu screen pfod message // send menu background, format, prompt, refresh and version parser.print(F("<+4>~SMS Hot Water\nControl`0")); parser.sendVersion(); // send the menu version // send menu items parser.print(F("|A<+4>")); parser.print('`'); parser.print(cmd_A_var); // output the current state 0 Low or 1 High parser.print(F("~Hot Water is ~~Off\\On~")); // Note the \\ inside the "'s to send \ ... parser.print(F("}")); // close pfod message } void sendMainMenuUpdate() { parser.print(F("{;")); // start an Update Menu pfod message // send menu items parser.print(F("|A")); parser.print('`'); parser.print(cmd_A_var); // output the current state 0 Low or 1 High parser.print(F("}")); // close pfod message // ============ end of menu =========== } int swap01(int in) { return (in==0)?1:0; } // ============= end generated code =========