Well, I tried this, but it doesn’t seem to be putting my Photon into listen mode. I’m not sure why. Here’s my code:
// This #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal.h>
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
#include "math.h"
// We're going to start by declaring which pins everything is plugged into.
int Probe1Pin = A0; //first probe
int Probe2Pin = A1; //second probe
//Declare variables
int probe1Value; // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor.
int probe2Value; // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor.
unsigned long loopMillis;
struct settings {
bool Probe1Enabled; //V0; true = we're using probe 1
bool Probe2Enabled; //V1; true = we're using probe 2
int Probe1MaxTemp; //V2; max temp for probe
int Probe1MinTemp; //V3; min temp for probe
int Probe2MaxTemp; //V4; max temp for probe
int Probe2MinTemp; //V5; min temp for probe
bool Probe1Notifications; //V6; true will send them
bool Probe2Notifications; //V7; true will send them
} s;
//Blynk init
char auth[] = "<redacted>";
// Make sure to update these to match how you've wired your pins.
// pinout on LCD [RS, EN, D4, D5, D6, D7];
// pin nums LCD [ 4, 6, 11, 12, 13, 14];
// Shield Shield [RS, EN, D4, D5, D6, D7];
// Spark Core [D3, D5, D2, D4, D7, D8];
LiquidCrystal lcd(D0, D1, D2, D3, D4, D5);
void setup() {
EEPROM.get(1, s); //get the settings from EEPROM
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
// Print a message to the LCD.
lcd.print("GRILL MONITOR V1");
delay(2000);
lcd.clear();
STARTUP(WiFi.selectAntenna(ANT_EXTERNAL)); // selects the u.FL antenna
// We are going to declare a Particle.variable() here so that we can access the value of the photoresistor from the cloud.
Particle.variable("probe1Value", &probe1Value, INT);
Particle.variable("probe2Value", &probe2Value, INT);
Blynk.begin(auth); //begin Blynk
}
void loop() {
//Check if WiFi is already established.
if (!WiFi.ready()) {
//Check if we are already waiting for WiFi to be ready and not listening for WiFi.
if (waitingMillis && !listeningForWiFi) {
//Check how long we have been waiting for WiFi to be ready.
if (millis() - waitingMillis > 30000) { //2 minutes wait time.
listeningForWiFi = true; //Set a flag so that we call WiFi.listen() once and not on every loop.
WiFi.listen(); //Put WiFi into listening mode.
}
} else {
//Record the time that we started waiting for WiFi to be ready.
waitingMillis = millis();
}
} else {
waitingMillis = 0; //Reset the waiting variable if WiFi is already established.
listeningForWiFi = false; //Reset the listening variable if WiFi is already established.
}
Blynk.run();
if (millis() - loopMillis > 5000UL) { //do this every 5 seconds
loopMillis = millis(); //update the timer
// check to see what the value of the photoresistor is and store it in the int variable analogvalue
probe1Value = thermister_temp(analogRead(Probe1Pin));
probe2Value = thermister_temp(analogRead(Probe2Pin));
gaugeColors();
if (s.Probe1Enabled) {
Blynk.virtualWrite(V10, probe1Value);
}
else {
Blynk.virtualWrite(V10, 0);
}
if (s.Probe2Enabled) {
Blynk.virtualWrite(V11, probe2Value);
}
else {
Blynk.virtualWrite(V11, 0);
}
//update wifi strength every 5 seconds
SendWIFIlevel();
updateLCD();
}
Send_Notifications();
}
int thermister_temp(int aval) {
double R, T;
// These were calculated from the thermister data sheet
// A = 2.3067434E-4;
// B = 2.3696596E-4;
// C = 1.2636414E-7;
//
// This is the value of the other half of the voltage divider
// Rknown = 22200;
// Do the log once so as not to do it 4 times in the equation
// R = log(((1024/(double)aval)-1)*(double)22200);
R = log((1 / ((4095 / (double) aval) - 1)) * (double) 22200);
//lcd.print("A="); lcd.print(aval); lcd.print(" R="); lcd.print(R);
// Compute degrees C
T = (1 / ((2.3067434E-4) + (2.3696596E-4) * R + (1.2636414E-7) * R * R * R)) - 273.25;
// return degrees F
return ((int) ((T * 9.0) / 5.0 + 32.0));
}
BLYNK_WRITE(V0) { //probe 1 enabled
s.Probe1Enabled = param.asInt();
EEPROM.put(1, s); //save the settings to EEPROM
if (s.Probe1Enabled) lcd.clear(); //remove the chars left on the display
}
BLYNK_WRITE(V1) { //probe 2 enabled
s.Probe2Enabled = param.asInt();
EEPROM.put(1, s); //save the settings to EEPROM
if (s.Probe1Enabled) lcd.clear(); //remove the chars left on the display
}
BLYNK_WRITE(V2) { //probe 1 max temp
s.Probe1MaxTemp = param.asInt();
EEPROM.put(1, s); //save the settings to EEPROM
}
BLYNK_WRITE(V3) { //probe 1 min temp
s.Probe1MinTemp = param.asInt();
EEPROM.put(1, s); //save the settings to EEPROM
}
BLYNK_WRITE(V4) { //probe 2 max temp
s.Probe2MaxTemp = param.asInt();
EEPROM.put(1, s); //save the settings to EEPROM
}
BLYNK_WRITE(V5) { //probe 2 min temp
s.Probe2MinTemp = param.asInt();
EEPROM.put(1, s); //save the settings to EEPROM
}
BLYNK_WRITE(V6) { //probe 1 notifications
s.Probe1Notifications = param.asInt();
EEPROM.put(1, s); //save the settings to EEPROM
}
BLYNK_WRITE(V7) { //probe 2 notifications
s.Probe2Notifications = param.asInt();
EEPROM.put(1, s); //save the settings to EEPROM
}
BLYNK_CONNECTED() {
Blynk.virtualWrite(V0, s.Probe1Enabled);
Blynk.virtualWrite(V1, s.Probe2Enabled);
Blynk.virtualWrite(V2, s.Probe1MaxTemp);
Blynk.virtualWrite(V3, s.Probe1MinTemp);
Blynk.virtualWrite(V4, s.Probe2MaxTemp);
Blynk.virtualWrite(V5, s.Probe2MinTemp);
Blynk.virtualWrite(V6, s.Probe1Notifications);
Blynk.virtualWrite(V7, s.Probe2Notifications);
}
void gaugeColors() {
//Set meat probe gauge colors
//Green if OK, Red if out of range
if (s.Probe1Enabled) {
if (probe1Value > s.Probe1MaxTemp) { //probe 1 is higher than normal
Blynk.setProperty(V10, "color", "#D3435C"); //change it to red
}
else if (probe1Value < s.Probe1MinTemp) { //probe 1 is less than normal
Blynk.setProperty(V10, "color", "#04C0F8"); //blue
}
else Blynk.setProperty(V10, "color", "#23C48E"); //green //set to normal color
}
else Blynk.setProperty(V10, "color", "#23C48E"); //green //set to normal color
//probe 2
if (s.Probe2Enabled) {
if (probe2Value > s.Probe2MaxTemp) { //probe 2 is higher than normal
Blynk.setProperty(V11, "color", "#D3435C"); //change it to red
}
else if (probe2Value < s.Probe2MinTemp) { //probe 2 is less than normal
Blynk.setProperty(V11, "color", "#04C0F8"); //blue
}
else Blynk.setProperty(V11, "color", "#23C48E"); //green //set to normal color
}
else Blynk.setProperty(V11, "color", "#23C48E"); //green //set to normal color
}
void Send_Notifications() {
static unsigned long prevMillis; //timer for notifications
if (millis() - prevMillis > 60000) { //only send notifications this often
if (s.Probe1Notifications && s.Probe1Enabled) {
if (probe1Value > s.Probe1MaxTemp) { //probe 1 is higher than normal
Blynk.notify("Probe 1 temperature is too high");
prevMillis = millis(); //reset timer
}
else if (probe1Value < s.Probe1MinTemp) { //probe 1 is less than normal
Blynk.notify("Probe 1 temperature is too low");
prevMillis = millis(); //reset timer
}
}
if (s.Probe2Notifications && s.Probe2Enabled) {
if (probe2Value > s.Probe2MaxTemp) { //probe 1 is higher than normal
Blynk.notify("Probe 2 temperature is too high");
prevMillis = millis(); //reset timer
}
else if (probe2Value < s.Probe2MinTemp) { //probe 1 is less than normal
Blynk.notify("Probe 2 temperature is too low");
prevMillis = millis(); //reset timer
}
}
}
}
void SendWIFIlevel() {
int rssi = WiFi.RSSI();
//WiFiSignal rssi = WiFi.RSSI();
Blynk.virtualWrite(V8, rssi);
}
void updateLCD() {
lcd.setCursor(0, 0);
if (s.Probe1Enabled) {
lcd.print("PROBE 1: ");
lcd.print(probe1Value);
lcd.write(0xdf);
lcd.print("F ");
}
else {
lcd.print("PROBE 1 DISABLED");
}
lcd.setCursor(0, 1);
if (s.Probe2Enabled) {
lcd.print("PROBE 2: ");
lcd.print(probe2Value);
lcd.write(0xdf);
lcd.print("F ");
}
else {
lcd.print("PROBE 2 DISABLED");
}
}