[SOLVED] Sending relay state from photon to ubidots


#1

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.


#2

Hello @fariqghani,

I just review your code and I found out that your are assigning the ubidots variable label with specials characters as spaces and that is not allowed in the Ubidots side. Please, try assigning the variable label as is shown below:

ubidots.add("pump-no-1", relayState);
ubidots.sendAll();

Instead of:

ubidots.add("Pump no. 1", relayState);
ubidots.sendAll();

If you desire after posting data to Ubidots you can modify your variable name. To get a better idea about the difference between labels and names you can reference to this article.

Referring to the SMS inconvenience, the Ubidots Educational Licenses just allow 5 SMS per month. In order of this, can you let us know if you already exceeded the limit? If, not please let us know to make the revision!

All the best,
Maria C.