all of my code on the sending ESP8266-01
//esp8266-01
#include <BlynkSimpleEsp8266.h>
#include <FS.h>
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <EEPROM.h>
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h>
//TIME
#include <NTPClient.h>
#include <WiFiUdp.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP,"pool.ntp.org");
String weekDays[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday"};
String months [12] = {"January","February","March","April","May","June","July","August","September","Octorber","November","December"};
int Date;
int Time;
int Total;
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing
char messageFromPC[numChars] = {0};
float floatFromPC = 0;
float floatFromPC2 = 0;
float floatFromPC3 = 0;
float floatFromPC4 = 50;
boolean newData = false;
String f;
String start = "start";
char Password[36]="";
char apiKey[16]="";
WiFiClient client;
char defaultHost[100] = ""; //Thing Speak IP address (sometime the web address causes issues with ESP's :/
long itt = 500;
long itt2 = 500;
const byte wifiResetPin = 13;
int interruptPinDebounce = 0;
long debouncing_time = 1000;
volatile unsigned long wifiResetLastMillis = 0;
char auth[] = "xxxxxxxxxxxxxxxxxx";
char ssid[] = "";
char pass[] = "";
int activate = 0;
int led = 0;
bool shouldSaveConfig = false;
void saveConfigCallback () {
Serial.println("Should save config");
shouldSaveConfig = true;}
void handleWifiReset(){
if(millis()<wifiResetLastMillis){
wifiResetLastMillis = millis();
}
if((millis() - wifiResetLastMillis)>= debouncing_time){
Serial.println("Clearing WiFi data resetting");
WiFiManager wifiManager;
wifiManager.resetSettings();
SPIFFS.format();
ESP.reset();
delay(1000);
}
wifiResetLastMillis = millis();
}
int addr = 0;
WidgetBridge bridge1(V1);
BLYNK_CONNECTED(){
bridge1.setAuthToken("XXXXXXXXXXXXXXXXXXX");
}
void setup() {
Serial.print("setup");
WiFiManager wifiManager;
Serial.begin(57600);
pinMode(wifiResetPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(wifiResetPin), handleWifiReset,FALLING);
WiFiManagerParameter customAPIKey("apiKey", "Time Zone #", apiKey, 16);
wifiManager.addParameter(&customAPIKey);
wifiManager.autoConnect("FloWT3");
Serial.println("Connected");
strcpy(apiKey,customAPIKey.getValue());
EEPROM.begin(512); //Initialize EEPROM
EEPROM.write(addr, 'A'); //Write character A
addr++; //Increment address
EEPROM.write(addr, 'B'); //Write character A
String www = apiKey;
for(int i=0;i<www.length();i++) //loop upto string lenght www.length() returns length of string
{
EEPROM.write(0x0F+i,www[i]); //Write one by one with starting address of 0x0F
}
EEPROM.commit(); //Store data to EEPROM
}
void loop()
{
delay(1000);
// ESP.wdtFeed(); // feeds the dog
//delay(0);
Serial.print("loop");
//new stuff string
recvWithStartEndMarkers();
if (newData == true) {
strcpy(tempChars, receivedChars);
// this temporary copy is necessary to protect the original data
// because strtok() used in parseData() replaces the commas with \0
parseData();
showParsedData();
newData = false;
}
//new stuff string end
delay(1000);
WiFiManager wifiManager;
if (WiFi.status() == WL_DISCONNECTED) {
wifiManager.autoConnect("FloWT3");
delay(60000);}
else if (WiFi.status() == WL_CONNECTED) { Serial.println("Connected");
delay(1000);
WiFiClient client;
long itt =50;
long itt2 = 200;
char defaultHost[100] = "api.thingspeak.com";
EEPROM.begin(512);
Serial.println(""); //Goto next line, as ESP sends some garbage when you reset it
Serial.print(char(EEPROM.read(addr))); //Read from address 0x00
addr++; //Increment address
Serial.print(char(EEPROM.read(addr))); //Read from address 0x01
addr++; //Increment address
Serial.println(char(EEPROM.read(addr))); //Read from address 0x02
//addr++; //Increment address
//Serial.println(char(EEPROM.read(addr))); //Read from address 0x03
//Read string from eeprom
String www;
//Here we dont know how many bytes to read it is better practice to use some terminating character
//Lets do it manually www.circuits4you.com total length is 20 characters
for(int i=0;i<16;i++)
{
www = www + char(EEPROM.read(0x0F+i)); //Read one by one with starting address of 0x0F
}
//TIME
timeClient.begin();
delay(1000);
timeClient.setTimeOffset(know*60*60);
timeClient.update();
unsigned long epochTime = timeClient.getEpochTime();
Serial.print("Epoch Time: ");
Serial.println(epochTime);
String formattedTime = timeClient.getFormattedTime();
int Time = formattedTime.toInt();
Serial.print("Formatted Time: ");
Serial.println(formattedTime);
int currentHour = timeClient.getHours();
Serial.print("Hour: ");
Serial.println(currentHour);
int currentMinute = timeClient.getMinutes();
Serial.print("Minutes: ");
Serial.println(currentMinute);
int currentSecond = timeClient.getSeconds();
Serial.print("Seconds: ");
Serial.println(currentSecond);
String weekDay = weekDays[timeClient.getDay()];
Serial.print("Week Day: ");
Serial.println(weekDay);
//Get a time structure
struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday;
Serial.print("Month day: ");
Serial.println(monthDay);
int currentMonth = ptm->tm_mon+1;
Serial.print("Month: ");
Serial.println(currentMonth);
String currentMonthName = months[currentMonth-1];
Serial.print("Month name: ");
Serial.println(currentMonthName);
int currentYear = ptm->tm_year+1900;
Serial.print("Year: ");
Serial.println(currentYear);
//Print complete date:
String currentDate = String(currentMonth) + "-" + String(monthDay) + "-" + String(currentYear) + " " + String(formattedTime);
Serial.print("Current date: ");
int Date = currentDate.toInt();
Serial.println(currentDate);
Serial.println("");
timeClient.end();
delay(2000);
Serial.println("auth");
Serial.print(auth);
client.stop();
if(floatFromPC4== 0){
activate =1;
led = 255;
}
if(floatFromPC4== 50){
activate =0;
}
if(floatFromPC4== 100){
activate =1;
led = 0;
}
if(floatFromPC4== 60){
activate =0;
}
Serial.println("Waiting…");
delay(2000);
Blynk.begin(auth,ssid,pass);
delay(2000);
bridge1.virtualWrite(V5,floatFromPC-31);
bridge1.virtualWrite(V8,currentDate);
delay(500);
bridge1.virtualWrite(V3,floatFromPC2-300);
int temperature1 = (floatFromPC3);
Serial.print("total");
bridge1.virtualWrite(V4,temperature1);
bridge1.virtualWrite(V7,floatFromPC4);
if(floatFromPC4 ==0){
bridge1.digitalWrite(14,HIGH);
delay(100);
bridge1.digitalWrite(14,LOW);
} if(floatFromPC4 ==50){
}
if(floatFromPC4 ==100){
bridge1.digitalWrite(14,HIGH);
delay(100);
bridge1.digitalWrite(14,LOW);
}
if(floatFromPC4 ==60){
}
}
}
//more new stuff for string
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
void parseData() { // split the data into its parts
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(tempChars,","); // get the first part - the string
strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
floatFromPC = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ",");
floatFromPC2 = atoi(strtokIndx); // convert this part to a float
strtokIndx = strtok(NULL, ",");
floatFromPC3 = atoi(strtokIndx); // convert this part to a float
strtokIndx = strtok(NULL, ",");
floatFromPC4 = atoi(strtokIndx); // convert this part to a float
}
void showParsedData() {
Serial.print("Message ");
Serial.println(messageFromPC);
Serial.print("water level ");
Serial.println(floatFromPC);
Serial.print("battery level ");
Serial.println(floatFromPC2);
Serial.print("temp F ");
Serial.println(floatFromPC3);
Serial.print("trip ");
Serial.println(floatFromPC4);
}
code for ESP8266-12e
#define BLYNK_PRINT Serial
//NodeMCU 1.0 (ESP-12E Module constant connect)
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//NEW AUTOCONNECT
#include <FS.h> //https://github.com/esp8266/Arduino
#include <EEPROM.h>
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h>
//NEW AUTOCONNECT
const byte numChars = 32;
char receivedChars[numChars];
char Password[36]="";
char apiKey[32]="";
char apiKey2[32]="";
char channelKey[16];
char channelKey2[16];
String channelKey21= "&";
char auth[] = "XXXXXXXXXXXXXXXXXXXX";
byte pinState = LOW;
char ssid[] = "";
char pass[] = "";
String Label = "";
String TOTAL = "";
WiFiClient client;
//NEW AUTOCONNECT
char defaultHost[100] = ""; //Thing Speak IP address (sometime the web address causes issues with ESP's :/
const byte wifiResetPin = 13;
int interruptPinDebounce = 0;
long debouncing_time = 1000;
volatile unsigned long wifiResetLastMillis = 0;
bool shouldSaveConfig = false;
int address = 0;
int LED = D5;
int pinValue = 65;
int pinValue2 = 65;
WidgetLED led1(V6);
int fire = 0;
int pinValue4;
int pinValue8 = 0;
String f;
byte value;
void saveConfigCallback () {
Serial.println("Should save config");
shouldSaveConfig = true;}
void handleWifiReset(){
if(millis()<wifiResetLastMillis){
wifiResetLastMillis = millis();
}
if((millis() - wifiResetLastMillis)>= debouncing_time){
Serial.println("Clearing WiFi data resetting");
WiFiManager wifiManager;
wifiManager.resetSettings();
SPIFFS.format();
ESP.reset();
delay(1000);
}
wifiResetLastMillis = millis();
}
int addr = 0;
//END NEW AUTOCONNECT
void setup() {
Serial.begin(115200);
pinMode(D5,OUTPUT);
digitalWrite(D5,LOW);
pinMode(LED,OUTPUT);
digitalWrite(LED,LOW);
led1.off();
led1.setValue(0);
//NEW AUTOCONNECT
WiFiManager wifiManager;
// put your setup code here, to run once:
pinMode(wifiResetPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(wifiResetPin), handleWifiReset,FALLING);
wifiManager.autoConnect("FloWT2");
Serial.println("Connected");
Serial.println("local ip");
Serial.println(WiFi.localIP());
delay (2000);
if (WiFi.status() == WL_DISCONNECTED) {
wifiManager.autoConnect("FloWT2");
delay(60000);}
if (WiFi.status() == WL_CONNECTED) { Serial.println("Connected");
delay(1000);
WiFiClient client;
delay(2000);
Serial.printf("SSID: %s\n", WiFi.SSID().c_str());
Serial.printf("SSID: %s\n", WiFi.psk().c_str());
String ssidString = WiFi.SSID().c_str();
String pskString = WiFi.psk().c_str();
f = String('<')+String("Hi")+String(',')+String(ssidString)+String(',')+String(pskString)+String('>');
delay (1000);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
client.stop();
delay(2000);
}
Blynk.begin(auth, ssid, pass);
Blynk.syncAll();
Serial.println("auth");
Serial.print(auth);
}
void loop() {
Blynk.run();
}
BLYNK_WRITE(V2){
int pinValue5 = param.asInt(); // Assigning incoming value from pin V5 to a variable
Serial.println(pinValue5);
Serial.print("Pin number: ");
Serial.println(LED);
Serial.print("Value read from Blynk ButtonPress: ");
Serial.println(pinValue5);
if(pinValue5 == 1 && pinValue8==255){
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED,LOW);// Turn LED on.
Blynk.notify("You just stopped filling your pool.");
Blynk.virtualWrite(V6,0);
Blynk.setProperty(V2,"label", " FULL");
Blynk.setProperty(V6,"label", " FULL");
Blynk.setProperty(V2,"offLabel", "TAP");
Blynk.setProperty(V2,"color", "#23C48E");
Blynk.setProperty(V6,"color", "#23C48E");
pinValue8 = 0;
}
else if (pinValue5 == 1 && pinValue8 == 0) {
digitalWrite(LED, HIGH); // Turn LED on.
delay(100);
digitalWrite(LED,LOW);
Blynk.notify("You just started filling your pool.");
Blynk.virtualWrite(V6,255);
Blynk.setProperty(V2,"label", " FILLING");
Blynk.setProperty(V6,"label", " FILLING");
Blynk.setProperty(V2,"onLabel", "");
Blynk.setProperty(V2,"color", "#D3435C");
Blynk.setProperty(V6,"color", "#D3435C");
pinValue8 = 255;
}
else {
digitalWrite(LED, LOW); // Turn LED off.
}}
BLYNK_WRITE(V5)
{
int pinValue = param.asInt(); // Assigning incoming value from pin V5 to a variable
Serial.println(pinValue);
if(pinValue<-29){
Blynk.notify("Your pool is dangerously low, try manually filling it with your Blynk App");
}
else if(pinValue>50){
Blynk.notify("Your pool is dangerously High, check to see if it is filling and stop it manually! ");
}}
BLYNK_WRITE(V8){
String pinValue9 = param.asString(); // Assigning incoming value from pin V5 to a variable
Serial.println(pinValue9);
Serial.println(Label);
if (pinValue9 != Label){
Label=pinValue9;
String Battery = "BATTERY LEVEL";
String space = " ";
TOTAL= Label + space + Battery;
Serial.println(Label);
Serial.println(TOTAL);
Blynk.setProperty(V3,"label", TOTAL);
}
}
BLYNK_WRITE(V3){
int pinValue2 = param.asInt(); // Assigning incoming value from pin V5 to a variable
Serial.println(pinValue2);
Blynk.setProperty(V3,"label", TOTAL);
if(pinValue2<=20){
Blynk.setProperty(V3,"color", "#D3435C");
Blynk.notify("Your batteries are not charging and may need to be changed!");
}
else if((pinValue2>20)&&(pinValue2<=50)){
Blynk.setProperty(V3,"color", "#ED9D00");
}
else if((pinValue2>50)&&(pinValue2<=130)){
Blynk.setProperty(V3,"color", "#23C48E");
}
else if(pinValue2>130){
Blynk.setProperty(V3,"color", "#D3435C");
Blynk.notify("Your batteries are overcharging!");
}
}
BLYNK_WRITE(V4){
int pinValue3 = param.asInt(); // Assigning incoming value from pin V5 to a variable
Serial.println(pinValue3);
if(pinValue3<70){
Blynk.setProperty(V4,"color", "#5F7CD8");
}
else if((pinValue3>=70)&&(pinValue3<90)){
Blynk.setProperty(V4,"color", "#23C48E");
}
else if(pinValue3>=90){
Blynk.setProperty(V4,"color", "#D3435C");
}
}
BLYNK_WRITE(V7)
{
int pinValue7 = param.asInt(); // Assigning incoming value from pin V5 to a variable
Serial.println(pinValue7);
if(pinValue7 == 0){
Blynk.notify("Your pool is low and just started filling.");
Blynk.virtualWrite(V6,255);
Blynk.setProperty(V2,"label", " FILLING");
Blynk.setProperty(V6,"label", " FILLING");
Blynk.setProperty(V2,"onLabel", "");
Blynk.setProperty(V2,"color", "#D3435C");
Blynk.setProperty(V6,"color", "#D3435C");
}
if(pinValue7 == 100){
Blynk.notify("Your pool is full and stopped filling.");
Blynk.virtualWrite(V6,0);
Blynk.setProperty(V2,"label", " FULL");
Blynk.setProperty(V6,"label", " FULL");
Blynk.setProperty(V2,"offLabel", "TAP");
Blynk.setProperty(V2,"color", "#23C48E");
Blynk.setProperty(V6,"color", "#23C48E");
}
if(pinValue7 == 50){
}
}
I THINK THIS IS EVERYTHING.