Esp8266 having “Cmd error”, runs good for a while then starts with the error and reconnects to Blynk server.
Looks like it does it when writing to V1 and V2.
//********** Blynk_ESP8266 **********
//*************************************
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define BLYNK_DEBUG
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "**************************************";
SimpleTimer timer;
//********** BasicOTA **********
//******************************
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
//********** Dallas Temp **********
//***********************************
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
//********** Adafruit MCP9808 **********
//***************************************
#include <Wire.h>
#include "Adafruit_MCP9808.h"
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
//********** LiquidCrystal_I2C **********
//*****************************************
#include <LiquidCrystal_I2C.h>
// Set the LCD address
LiquidCrystal_I2C lcd(0x3F, 20, 4);
byte thermometer[8] = //icon for thermometer
{
B00100,
B01010,
B01010,
B01010,
B01110,
B11111,
B11111,
B01110
};
byte waterDroplet[8] = //icon for water droplet
{
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};
int officeTemp;
int officeHumd;
int shopTemp;
int shopHumd;
int garageTemp;
int mainDoor;
int thirdDoor;
int shopDoor;
int sideDoor;
int ledPin = 14;
// WiFi credentials.
char ssid[] = "******************";
char pass[] = "********************";
IPAddress device_ip (192, 168, 1, 52);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip (192, 168, 1, 1);
IPAddress subnet_mask(255, 255, 255, 0);
//********** Get and Print Temp Readings **********
//**************************************************
void temp()
{
// Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
// Serial.println("DONE");
float outTemp = sensors.getTempFByIndex(0)+1.7;
// Serial.println("wake up MCP9808.... "); // wake up MSP9808 - power consumption ~200 mikro Ampere
tempsensor.shutdown_wake(0); // required before reading temp
// Read and print out the temperature
float inTemp = tempsensor.readTempC() * 9.0 / 5.0 + 32;
delay(250);
// Serial.println("Shutdown MCP9808.... ");
tempsensor.shutdown_wake(1); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere
Serial.println();
Serial.print("DS18B20 Temp: "); Serial.print(outTemp, 1);
Serial.print("\tMCP9808 Temp: "); Serial.println(inTemp, 1);
Blynk.virtualWrite(1, outTemp); // virtual pin
Blynk.virtualWrite(2, inTemp); // virtual pin
Serial.println();
//********** Print to LCD **********
//**********************************
lcd.setCursor(0,0);
lcd.print ("Out ");lcd.write(1);lcd.print (" ");
lcd.print (outTemp, 0); lcd.print((char)223); // print degree symbol
lcd.print ("F");
lcd.print (" In "); lcd.write(1);lcd.print (" ");
lcd.print (inTemp, 0); lcd.print((char)223); // print degree symbol
lcd.print ("F");
lcd.setCursor(0,1);
lcd.print ("Office "); lcd.write(1);lcd.print (" ");
lcd.print (officeTemp); lcd.print((char)223); // print degree symbol
lcd.print ("F ");
lcd.write(2);lcd.print (" "); lcd.print (officeHumd);lcd.print ("% ");
lcd.setCursor(0,2);
lcd.print ("Shop "); lcd.write(1);lcd.print (" ");
lcd.print (shopTemp); lcd.print((char)223); // print degree symbol
lcd.print ("F ");
lcd.write(2);lcd.print (" "); lcd.print (shopHumd);lcd.print ("%");
lcd.setCursor(0,3);
lcd.print ("Garage "); lcd.write(1);lcd.print (" ");
lcd.print (garageTemp); lcd.print((char)223); // print degree symbol
lcd.print ("F");
}
void checkDoors ()
{
if (mainDoor == 1 || thirdDoor == 1 || shopDoor == 1){
digitalWrite (ledPin, HIGH);
}
else {
digitalWrite (ledPin, LOW);
}
}
void setup()
{
Serial.begin(9600);
// Setup WiFi network
Serial.println();
Serial.println("Booting");
WiFi.mode(WIFI_STA);
WiFi.config(device_ip, gateway_ip, subnet_mask);
WiFi.begin(ssid, pass);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
// Setup Blynk
Blynk.config(auth);
while (Blynk.connect() == false) {
}
timer.setInterval(10000L, temp);
timer.setInterval(2000L, checkDoors);
sensors.begin();
// Make sure the sensor is found, you can also pass in a different i2c
// address with tempsensor.begin(0x18) for example
if (!tempsensor.begin()) {
Serial.println("Couldn't find MCP9808!");
while (1);
}
// initialize the LCD
lcd.begin();
// Turn on the blacklight
lcd.backlight();
lcd.clear();
lcd.createChar(1,thermometer);
lcd.createChar(2,waterDroplet);
pinMode (ledPin, OUTPUT);
//********** OTA Program **********
//*********************************
// Port defaults to 8266
// ArduinoOTA.setPort(8266);
// Hostname defaults to esp8266-[ChipID]
// ArduinoOTA.setHostname("myesp8266");
// No authentication by default
// ArduinoOTA.setPassword((const char *)"123");
ArduinoOTA.onStart([]() {
Serial.println("Start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
ESP.restart();
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
//********** Reading from Office **********
//*******************************************
BLYNK_WRITE(V11){
officeTemp = param.asInt(); //pinData variable will store value that came via Bridge
// Serial.print ("Office Temp: "); Serial.println (officeTemp);
}
BLYNK_WRITE(V12){
officeHumd = param.asInt(); //pinData variable will store value that came via Bridge
// Serial.print ("Office Humd: "); Serial.println (officeHumd);
}
//********** Reading from Shop **********
//*****************************************
BLYNK_WRITE(V13){
shopTemp = param.asInt(); //pinData variable will store value that came via Bridge
// Serial.print ("Shop Temp: "); Serial.println (shopTemp);
}
BLYNK_WRITE(V14){
shopHumd = param.asInt(); //pinData variable will store value that came via Bridge
// Serial.print ("Shop Humd: "); Serial.println (shopHumd);
}
//********** Reading from Garage **********
//*******************************************
BLYNK_WRITE(V15) {
garageTemp = param.asInt(); //pinData variable will store value that came via Bridge
// Serial.print ("Garage Temp: "); Serial.println (garageTemp);
}
//********** Shop Door **********
//********************************
BLYNK_WRITE(V16) {
shopDoor = param.asInt(); //pinData variable will store value that came via Bridge
}
//********** Main Door **********
//********************************
BLYNK_WRITE(V17) {
mainDoor = param.asInt(); //pinData variable will store value that came via Bridge
}
//********** 3rd Door **********
//*******************************
BLYNK_WRITE(V18) {
thirdDoor = param.asInt(); //pinData variable will store value that came via Bridge
}
//********** Shop Side Door **********
//*************************************
BLYNK_WRITE(V19) {
sideDoor = param.asInt(); //pinData variable will store value that came via Bridge
}
void loop(){
ArduinoOTA.handle();
Blynk.run();
timer.run();
}
DS18B20 Temp: 51.0 MCP9808 Temp: 70
[2519605] <[14|01]þ[00|0B]vw[00]1[00]51.025
[2524606] Cmd error
[2524608] Cmd skipped:20
[2524716] Connecting to blynk-cloud.com:8442
[2524811] <[02|00|01|00] c5537fa8e1474d7fb49c4f8dff53c249
[2524867] >[00|00|01|00]È
[2524867] Ready (ping: 1ms).
[2524867] <[11|02|00|00]Gver[00]0.4.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]ESP-12[00]build[00]Jan 19 2017 14:17:07[00]
[2524979] >[00|02|00|00]È
[2525541] >[0F|0F]±[00|07]
[2525541] >vw[00]17[00]1
[2525542] >[0F|0F]³[00|07]
[2525542] >vw[00]18[00]0
[2525620] >[0F|03]¾[00|0C]
[2525620] >vw[00]13[00]72.500
[2525628] >[0F|03]À[00|0C]
[2525628] >vw[00]14[00]29.700
[2525644] >[0F|03]Â[00|07]
[2525673] >vw[00]16[00]0
[2526463] >[0F|0F]µ[00|07]
[2526463] >vw[00]17[00]1
[2526526] >[0F|0F]·[00|07]
[2526526] >vw[00]18[00]0
[2526558] >[0F|08]p[00|08]
[2526558] >vw[00]15[00]70
[2527384] >[0F|03]Ä[00|07]
[2527384] >vw[00]16[00]0
[2527437] >[0F|0F]¹[00|07]
[2527437] >vw[00]17[00]1
[2527589] >[0F|0F]»[00|07]
[2527589] >vw[00]18[00]0
[2528511] >[0F|0F]¾[00|07]
[2528511] >vw[00]17[00]1
DS18B20 Temp: 51.0 MCP9808 Temp: 70
[2529605] <[14|02|01|00|0B]vw[00]1[00]51.025
[2534606] Cmd error
[2534608] Cmd skipped:20
[2534716] Connecting to blynk-cloud.com:8442
[2534811] <[02|00|01|00] c5537fa8e1474d7fb49c4f8dff53c249
[2534861] >[00|00|01|00]È
[2534861] Ready (ping: 1ms).
[2534861] <[11|02|03|00]Gver[00]0.4.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]ESP-12[00]build[00]Jan 19 2017 14:17:07[00]
[2534977] >[00|02|03|00]È
[2535437] >[0F|0F]Ú[00|07]
[2535437] >vw[00]17[00]1
[2535525] >[0F|0F]Ü[00|07]
[2535525] >vw[00]18[00]0
[2535617] >[0F|03]Í[00|0C]
[2535617] >vw[00]13[00]72.140
[2535618] >[0F|03]Ï[00|0C]
[2535618] >vw[00]14[00]29.700
[2535618] >[0F|03]Ñ[00|07]
[2535637] >vw[00]16[00]0
[2536439] >[0F|0F]Þ[00|07]
[2536439] >vw[00]17[00]1
[2536535] >[0F|0F]à[00|07]
[2536535] >vw[00]18[00]0
[2536565] >[0F|08]s[00|08]
[2536565] >vw[00]15[00]70
[2537343] >[0F|03]Ó[00|07]
[2537343] >vw[00]16[00]0
[2537437] >[0F|0F]â[00|07]
[2537437] >vw[00]17[00]1
[2537524] >[0F|0F]ä[00|07]
[2537524] >vw[00]18[00]0
[2538437] >[0F|0F]æ[00|07]
[2538437] >vw[00]17[00]1
[2538525] >[0F|0F]è[00|07]
[2538525] >vw[00]18[00]0
DS18B20 Temp: 51.0 MCP9808 Temp: 70
[2539605] <[14|02|04|00|0B]vw[00]1[00]51.025
[2539689] <[14|02|05|00|07]vw[00]2[00]70