/*
web_button.ino
Part of "Intel IoT Edison web controlled LED demo"
Copyright 2014 Pavlos Iliopoulos, techprolet.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#include "rgb_lcd.h"
#include "text_reader.c"
// const char * delimiter = " ,.-";
const char * delimiter = "\n";
char * str;
char * pch;
rgb_lcd lcd;
int ledPin = 13;
bool ledStatus = false;
bool lastLedStatus = false;
bool stringIsOk = false;
String remoteIp;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin,LOW);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setRGB(0,0,0);
// Print a message to the LCD.
lcd.print("Remote IP:");
delay (1000);
}
void loop() {
// put your setup code here, to run once:
str = readFile();
pch = strtok (str, delimiter);
if (pch != NULL){
ledStatus = (String(pch) == "true");
pch = strtok (NULL, delimiter);
remoteIp = String (pch);
pch = strtok (NULL, delimiter);
stringIsOk = String (pch) == "OK";
//read the rest of the string, you can omit this
while ((pch != NULL))
{
pch = strtok (NULL, delimiter);
}
}
if (stringIsOk && (ledStatus!=lastLedStatus)){
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin,ledStatus);
Serial.println (ledStatus);
//first, empty the screen from the old address
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setRGB(0,0,ledStatus?255:00);
lcd.setCursor(0, 1);
lcd.print(remoteIp);
Serial.println(remoteIp);
Serial.println("-------------------");
lastLedStatus = ledStatus;
}
delay(100);
}