0% found this document useful (0 votes)
36 views2 pages

pfodSMS SIM900

This JSON document contains code for controlling an LED connected to pin D3 of an Arduino board using SMS commands received via a GPRS shield. The code initializes serial communication and the GPRS module, defines the pin, and includes libraries for SMS handling and parsing commands. It then enters a loop to continuously parse commands and take appropriate actions like turning the pin on or off.

Uploaded by

elmerpabel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

pfodSMS SIM900

This JSON document contains code for controlling an LED connected to pin D3 of an Arduino board using SMS commands received via a GPRS shield. The code initializes serial communication and the GPRS module, defines the pin, and includes libraries for SMS handling and parsing commands. It then enters a loop to continuously parse commands and take appropriate actions like turning the pin on or off.

Uploaded by

elmerpabel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

new 1

Tuesday, March 24, 2015 4:47 AM

/* ===== pfod Command for Led Control ====


{.<w><+5><b>Using GPRS shield to turn D3 on and off via SMS|A~<+4><b>Pin D3 is
`0~~Low\High}
*/
// 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.572
* (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
*/
// Download library from http://www.forward.com.au/pfod/pfodParserLibraries/index.html
#include <EEPROM.h>
#include <pfodSMS_SIM900.h>
#include <pfodSecurity.h>
pfodSMS_SIM900 pfodSMS; // create object to handle SMS messages
pfodSecurity parser; // 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_pin = 3; // name the output pin for 'Pin D3 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 'Pin D3 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
-1-

new 1

Tuesday, March 24, 2015 4:47 AM

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 -- 'Pin D3 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("<w><+5><b>Using GPRS shield to turn D3 on and off via SMS"));
// send menu items
parser.print(F("|A~<+4><b>Pin D3 is\n`"));
parser.print(digitalRead(cmd_A_pin)); // read current output state 0 Low or 1 High
parser.print(F("~~Low\\High")); // Note the \\ inside the "'s to send \
// ============ end of menu item ===========
}
// ============= end generated code =========

-2-

You might also like