Hi, I am stuck. I have 2 arduino Uno board using ESP8266 as a shield.
This code works on another UNO board but im not exactly sure whats going on, I am getting a Connected to Wifi and even see the board show up on my router network but nothing else is being executed. Enabling debug also does not product additional output
Here’s my code:
blynk@1.3.2
/*************************************************************
WARNING!
It's very tricky to get it working. Please read this article:
http://help.blynk.cc/hardware-and-libraries/arduino/esp8266-with-at-firmware
This is a simple demo of sending and receiving some data.
Be sure to check out other examples!
*************************************************************/
/* Fill-in information from Blynk Device Info here */
// // DEBUG CREDENTIAL
#define BLYNK_TEMPLATE_ID "REDACTED"
#define BLYNK_TEMPLATE_NAME "REDACTED"
#define BLYNK_AUTH_TOKEN "REDACTED"
#define BLYNK_NO_BUILTIN // Disable built-in analog & digital pin operations https://docs.blynk.io/en/blynk-library-firmware-api/other
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG // Optional, this enables more detailed prints
void(* resetFunc) (void) = 0; //declare reset function @ address
#define ESP8266_USE_SOFTWARE_SERIAL
#include <ESP8266_Lib.h> // https://github.com/vshymanskyy/BlynkESP8266/tree/master
#include <BlynkSimpleShieldEsp8266.h>
/**
Outpins Start
**/
const int kalkPin = 8;
/**
Outpins End`
**/
/**
CONST
**/
const int relayOn = LOW; //TODO flip this, for debugging
const int relayOff = HIGH;
int kalkState = relayOff; // Kalk relay start state
const int KALK_INTERVAL_MINUTES = 180;
const int KALK_REPORT_MINUTES = 5;
unsigned long previousKalkMillis = 0;
//TODO look into this time https://docs.blynk.io/en/blynk.apps/widgets-interface/time-input
/*
Atlas PH Setup
*/
const int atlasPhPin = A5;
// to use the Atlas gravity circuits with
// the gravity isolator board's pulse output
// uncomment line 8: #define USE_PULSE_OUT
// you can use any pins instead of just the analog ones
// but it must be recalibrated
// note that the isolator's analog output also provides isolation
// TODO check out this code : https://www.hackster.io/atlasscientific/arduino-ph-meter-e94fb4
// #define USE_PULSE_OUT
#ifdef USE_PULSE_OUT
#include "ph_iso_grav.h"
Gravity_pH_Isolated pH = Gravity_pH_Isolated(atlasPhPin);
#else
#include "ph_grav.h"
Gravity_pH pH = Gravity_pH(atlasPhPin);
#endif
/*
Atlas PH End Setup
*/
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "REDACTED";
char pass[] = "REDACTED";
int reconnectCount = 0;
const int ledPin = LED_BUILTIN;
int ledState = LOW;
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX NOTE !!! ESP_RX -> UNO_TX_3 and ESP_TX -> UNO_RX_2 NO GPIO_0 to gnd!
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600 // To change baud on esp8266 board, AT+UART_DEF=9600,8,1,0,0
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
// Set incoming value from pin V0 to a variable
int value = param.asInt();
if (value == 1){
digitalWrite(kalkPin, relayOn);
Blynk.virtualWrite(V1, 0);
}else{
digitalWrite(kalkPin, relayOff);
Blynk.virtualWrite(V1, 1);
}
}
BLYNK_WRITE(V5)
{
String value = param.asStr();
// Turn on led as indicator
String msg;
if (value == "cal7"){
pH.cal_mid();
msg = "CALIBRATED 07";
}else if (value == "cal10"){
pH.cal_high();
msg = "CALIBRATED 10";
}else if (value == "cal4"){
pH.cal_low();
msg = "CALIBRATED 04";
}else if (value == "calClear"){
pH.cal_clear();
msg = "CALIBRATED 00";
}
if (msg != NULL){
digitalWrite(13, HIGH);
Blynk.virtualWrite(V6, msg);
msg.reserve(0); // Weird thing where multiple calls to write virtual pin causes problem. solution found here : https://community.blynk.cc/t/esp8266-stack-when-write-string-value-to-virturalpin/65501
timer.setTimeout(5000L, debugLEDOff);
}
}
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
BLYNK_LOG("CONNECTED!");
digitalWrite(12,LOW);
// Request Blynk server to re-send latest values for all pins
Blynk.syncAll();
int value = millis() / 1000;
Blynk.virtualWrite(V2, value);
Blynk.virtualWrite(V4, reconnectCount);
}
BLYNK_DISCONNECTED()
{
BLYNK_LOG("Disconnected, attemping to reconnect!");
int retryCount = 0;
Serial.print("DEBUG IN DISCUONNECTED: ");
Serial.print(wifi.kick());
Serial.print(": ");
Serial.println(wifi.getLocalIP());
while (!Blynk.connect(30)){
BLYNK_LOG("Attemping reconnect in forever loop!");
reconnectCount += 1;
digitalWrite(12,HIGH);
retryCount += 1;
if (retryCount > 4){
resetFunc(); //call reset on arduino
}
}
}
void livenessEvent()
{
Blynk.virtualWrite(V2, millis() / 1000);
}
void lastKalkDose(){
// Calculate time since last kalk dosing
int lastKalk = (millis() - previousKalkMillis) / 60000; // convert to minutes
Blynk.virtualWrite(V8, lastKalk );
}
// This function sends Arduino's uptime every second to Virtual Pin 2.
void phReadEvent()
{
float currentPh = pH.read_ph();
Blynk.virtualWrite(V3, currentPh);
Serial.print("PH: ");
Serial.println(currentPh);
}
void kalkOnTimer()
{
digitalWrite(kalkPin, relayOn);
timer.setTimeout(15000, kalkOffTimer);
previousKalkMillis = millis();
lastKalkDose();
Blynk.virtualWrite(V1, 0);
timer.setTimeout(10500, alertV2Off);
}
void alertV2Off(){
Blynk.virtualWrite(V1, 1);
}
void kalkOffTimer()
{
digitalWrite(kalkPin, relayOff);
}
void debugLEDOff(){
digitalWrite(13, LOW);
}
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(12, OUTPUT);
pinMode(kalkPin, OUTPUT);
digitalWrite(kalkPin, kalkState);
digitalWrite(12, HIGH);
// Debug console
Serial.begin(115200);
// Set ESP8266 baud rate
BLYNK_LOG("Start esp serial");
EspSerial.begin(ESP8266_BAUD);
delay(10);
if(wifi.restart()){
Serial.println("Restart failed on esp");
}
delay(1000);
BLYNK_LOG("Completed restart of esp");
Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
BLYNK_LOG("DEBUG GOT PASS BEGIN");
// Setup liveness
timer.setInterval(5800, livenessEvent);
// Setup a function to be called every second
timer.setInterval(4000L, phReadEvent);
timer.setInterval(KALK_REPORT_MINUTES * 60 * 1000L, lastKalkDose);
// Kalk Timer On/Off
timer.setInterval(KALK_INTERVAL_MINUTES * 60 * 1000L, kalkOnTimer);
// PH Meter setup
if (pH.begin()) {
BLYNK_LOG("ph.begin(): Loaded EEPROM");
}
}
void loop()
{
Blynk.run();
timer.run();
}
Here’s my logs
20:11:00.430 -> �[0] Start esp serial
20:11:05.578 -> Restart failed on esp
20:11:06.604 -> [4575] Completed restart of esp
20:11:06.604 -> [4575]
20:11:06.604 -> ___ __ __
20:11:06.604 -> / _ )/ /_ _____ / /__
20:11:06.604 -> / _ / / // / _ \/ '_/
20:11:06.604 -> /____/_/\_, /_//_/_/\_\
20:11:06.604 -> /___/ v1.3.2 on Arduino Uno
20:11:06.604 ->
20:11:06.604 -> #StandWithUkraine https://bit.ly/swua
20:11:06.604 ->
20:11:06.604 ->
20:11:07.093 -> [5089] Connecting to REDACTED
20:11:10.324 -> [8316] AT version:1.7.5.0(Oct 9 2021 09:26:04)
20:11:10.380 -> SDK version:3.0.5(b29dcd3)
20:11:10.380 -> compile time:Oct 15 2021 18:05:30
20:11:10.380 -> Bin version(Wroom 02):1.7.5
20:11:10.380 -> OK
20:11:14.586 -> [12548] +CIFSR:STAIP,"192.168.1.89"
20:11:14.586 -> +CIFSR:STAMAC,"8c:aa:b5:c9:a4:6b"
20:11:14.586 -> [12549] Connected to WiFi