Hi everyone.
I’m trying to send relay state to ubidots, which is 1 when then relay is energized, and 0 when in relax state.
Sometimes ubidots gets the reading, but most of the time nothing happens.
#include "Particle.h"
#include <blynk.h>
#define BLYNK_PRINT Serial
#include <Ubidots.h>
#define TOKEN "ubidots token"
Ubidots ubidots(TOKEN);
char auth[] = "auth key";
char oldRelayState = D3;
// Register the LED to virtual pin 1.
WidgetLED ledWidget(V4);
void setup()
{
//Set the LED pin as output.
pinMode(D7,OUTPUT);
//Set the Button 0 as input.
pinMode(D3,INPUT);
Serial.begin(115200);
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
char newRelayState = digitalRead(D3);
if (newRelayState !=oldRelayState)
{
int relayState;
if (newRelayState == HIGH)
{
ledWidget.on();
Particle.publish("Pump No. 1 : ", "TRIP");
relayState = 1;
delay(500);
}
else
{
ledWidget.off();
Particle.publish("Pump No. 1 : ", "OKAY");
relayState = 0;
delay(500);
}
ubidots.add("Pump no. 1", relayState);
ubidots.sendAll();
relayState = 0;
}
oldRelayState = newRelayState;
delay(1000);
}
Also, I’ve set event: sms me when the relay state is 1. But when ubidots get the 1, I’ve never received the sms. Credit was deducted though.