Hi There
I am developing with Photon and a Blynk apps.
The project is about to send from other microcontroler 5 sensor analog reading converted to 5 char arrays to the photon using serial.
I have the same project working OK since the last November but just for one sensor. On the project I am refer to in this post I repeat the one sensor snippet for the others ones.
The photon get connected and disconnected periodically going through breathing cyan, fast green, many short red blink an so on.
I am using the serial 1 for the photon.
The baud-rate for the photon and the other microcontroller are setting to the same value (Just for you to know it).
First, I consulted with Blynk forum and they told me that in the void loop, there are five “if” that runs thousand times for second. Then, they suggest I should use some Photon timer and not a Blynk Timer.
My point is to know what timer do you recommend me to use in this case.
I will appreciate very much your helps.
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
#define BLYNK_printserial
char auth[] = "745cf23fe70543bcbfcd68673d82e3ff" ;
char Lbs_1[6]; // 1th sensor array
char Lbs_2[6]; // 2th sensor array
char Lbs_3[6]; // 3th sensor array
char Lbs_4[6]; // 4th sensor array
char Lbs_5[6]; // 5th sensor array
BlynkTimer timer;
int Email_1=0;
const unsigned long SendEmail=17000L;
unsigned long lastEmail; // Global initialize to 0
const unsigned long SendLbs_1=1000L;
unsigned long lastLbs_1; // Global initialize to 0
const unsigned long SendLbs_2=1000L;
unsigned long lastLbs_2; // Global initialize to 0
const unsigned long SendLbs_3=1000L;
unsigned long lastLbs_3; // Global initialize to 0
const unsigned long SendLbs_4=1000L;
unsigned long lastLbs_4; // Global initialize to 0
const unsigned long SendLbs_5=1000L;
unsigned long lastLbs_5; // Global initialize to 0
void sendPressure_1()
{
int i=0;
while( Serial1.available() && i<7)
{
Lbs_1[i]=Serial1.read();
if (Lbs_1[i]=='\0;' )
{
break;
}
i++;
}
i=0;
Lbs_1[6]='\0';
/* Send it over the Blynk server */
Blynk.virtualWrite (V7,Lbs_1);
}
void sendPressure_2()
{
int i=0;
while( Serial1.available() && i<7)
{
Lbs_2[i]=Serial1.read();
if (Lbs_2[i]=='\0;' )
{
break;
}
i++;
}
i=0;
Lbs_2[6]='\0';
/* Send it over the Blynk server */
Blynk.virtualWrite (V8,Lbs_2);
}
void sendPressure_3()
{
int i=0;
while( Serial1.available() && i<7)
{
Lbs_3[i]=Serial1.read();
if (Lbs_3[i]=='\0;' )
{
break;
}
i++;
}
i=0;
Lbs_3[6]='\0';
/* Send it over the Blynk server */
Blynk.virtualWrite (V9,Lbs_3);
}
void sendPressure_4()
{
int i=0;
while( Serial1.available() && i<7)
{
Lbs_4[i]=Serial1.read();
if (Lbs_4[i]=='\0;' )
{
break;
}
i++;
}
i=0;
Lbs_4[6]='\0';
/* Send it over the Blynk server */
Blynk.virtualWrite (V10,Lbs_4);
}
void sendPressure_5()
{
int i=0;
while( Serial1.available() && i<7)
{
Lbs_5[i]=Serial1.read();
if (Lbs_5[i]=='\0;' )
{
break;
}
i++;
}
i=0;
Lbs_5[6]='\0';
/* Send it over the Blynk server */
Blynk.virtualWrite (V11,Lbs_5);
}
void SEmail()
{
while( Serial1.available()>0)
{
Email_1=Serial1.read();
if (Email_1==0xAA)
{
Blynk.email("Subjet","Lbs_1>250");
Email_1 =0; break;
}
}
}
void setup() {
// Debug Console
Serial1.begin(57600);
delay(5000);// Allow board to settle
Blynk.begin (auth);
}
void loop() {
unsigned long topLoop_1 = millis();
//unsigned long topLoop_2 = millis();
//unsigned long topLoop_3 = millis();
//unsigned long topLoop_4 = millis();
//unsigned long topLoop_5 = millis();
Blynk.run();
if ((topLoop_1-lastLbs_1 )>=SendLbs_1)
{
lastLbs_1=topLoop_1;
sendPressure_1();
}
if ((topLoop_1-lastLbs_2 )>=SendLbs_2)
{
lastLbs_2=topLoop_1;
sendPressure_2();
}
if ((topLoop_1-lastLbs_3 )>=SendLbs_3)
{
lastLbs_3=topLoop_1;
sendPressure_3();
}
if ((topLoop_1-lastLbs_4 )>=SendLbs_4)
{
lastLbs_4=topLoop_1;
sendPressure_4();
}
if ((topLoop_1-lastLbs_5 )>=SendLbs_5)
{
lastLbs_5=topLoop_1;
sendPressure_5();
}
}