Hi
i wrote some code which simply displays the state of an input on ubidots. I put a cause that the state must have changed before the data is sent however when i woke up in the morning all my data was gone even though no inputs had changed (they are manual switches on my test rig). can anyone see where i have gone wrong?
I currently don’t use the analog value as yet
Thanks…Ben
// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>
// This #include statement was automatically added by the Particle IDE.
#include <SegmentDriver.h>
// This #include statement was automatically added by the Particle IDE.
#include <NCD2Relay.h>
#define TOKEN "????????????????????????????" // Put here your Ubidots TOKEN
Ubidots ubidots(TOKEN);
SegmentLEDDriver display; // create an instance of the LED Display
NCD2Relay relayController; // create an instance of the board
int input1 = 0;
int lastinput1 = 0;
int input2 = 0;
int lastinput2 = 0;
int input3 = 0;
int lastinput3 = 0;
int input4 = 0;
int lastinput4 = 0;
float analog1 = 0.0;
int testvar = 0; // used to set the LED display to 0
void setup()
{
Serial.begin(115200);
relayController.setAddress(0,0,0);// set the address of the relay board
relayController.turnOffRelay(1); // turn off relay 1 on the board if it is on
relayController.turnOffRelay(2); // turn off relay 2 on the board if it is on
display.init();
}
void loop() {
//---------------------------------Read all the inputs----------------------
input1 = relayController.readInputStatus(1);
input2 = relayController.readInputStatus(2);
input3 = relayController.readInputStatus(3);
input4 = relayController.readInputStatus(4);
analog1 = analogRead(A0);
analog1 = map(analog1, 0, 4095, 4, 20);
display.displayWriteInt(testvar);// display on lcd testvar variable
//---------------------------------------Check if anything is diffrent then update web
if (input1 != lastinput1)
{
lastinput1 = input1;
ubidots.add("input1", input1);
ubidots.sendAll();
testvar ++;
delay(1000);
}
if (input2 != lastinput2)
{
lastinput2 = input2;
ubidots.add("input2", input2);
ubidots.sendAll();
testvar ++;
delay(1000);
}
if (input3 != lastinput3)
{
lastinput3 = input3;
ubidots.add("input3", input3);
ubidots.sendAll();
testvar ++;
delay(1000);
}
if (input4 != lastinput4)
{
lastinput4 = input4;
ubidots.add("input4", input4);
ubidots.sendAll();
testvar ++;
delay(1000);
}
}