How to control switch in ubidots with arduino logger


#1

I am using ubidots esp8266 serial library, and using control switch to send 0 or 1 to my arduino logger but nothing happens.I am receiving only -1 in both on/off
here is my arduino code:

    void loop(){
     
    namespace {
      bool flow_control = true; // control the flow of the requests
      const char * USER_AGENT = "UbidotsESP8266"; // Assgin the user agent
      const char * VERSION =  "1.0"; // Assign the version
      const char * METHOD = "POST"; // Set the method
      const char * METHOD1 = "LV"; // Set the method
      const char * TOKEN = "A1E-G1uLiPw5qumgp5rP1kRFALMOahYMuc"; // Assign your 
      const char * DEVICE_LABEL = "esp8266"; // Assign the device label
       const char * VARIABLE_LABEL5 = "forward"; // Assign the variable label
      const char * VARIABLE_ID5 = "5cec8176c03f97793e27aab3"; // Assign the variable label
    }


      char* command = (char *) malloc(sizeof(char) * 128);
      /* Wait for the server response to read the values and built the command */
      /* While the flag is true it will take the sensors readings, build the command,
         and post the command to Ubidots */
      if (flow_control) {
        /* Analog reading */
           


        /* Building the logger command */
        
        sprintf(command, "init#");
        sprintf(command, "%s%s/%s|%s|%s|", command, USER_AGENT, VERSION, METHOD1, TOKEN);
        sprintf(command, "%s%s=>", command, DEVICE_LABEL);
        sprintf(command, "%s%s:%s", command, VARIABLE_LABEL5);
        sprintf(command, "%s|end#final", command);
      


        /* Prints the command sent */
        Serial.println(command);// uncomment this line to print the command


        /* Sends the command to the telemetry unit */
       float c= Serial1.read();
        Serial.println(c);
        /* free memory*/
        free(command);
        
        /* Change the status of the flag to false. Once the data is sent, the status
           of the flag will change to true again */
        flow_control = false;
      }


      /* Reading the telemetry unit */
      int i = 0;
      while (Serial1.available() > 0) {
        telemetry_unit[i++] = (char)Serial1.read();
        /* Change the status of the flag; allows the next command to be built */
        flow_control = true;
      }


      


      if (flow_control) {
        /* Print the server response -> OK */
        Serial.write(telemetry_unit);
        /* free memory */
        memset(telemetry_unit, 0, i);
      }


      delay(100); 

    }

#2

Greetings, please refer to our examples to know how to build a TCP request to retrieve data from Ubidots.

All the best


#3

Sir, I am using esp8266 as telemetry device with arduino as logger.
But I am not receiving any data when I am using GET/LV command.
My esp8266 only returns -1 then error message.
Kindly suggest me how i can use the correct logger command to receive data from ubidots at my arduino through esp8266. I have given my arduino code above.


#4

Greetings, please refer to the library official example and make sure to change the method from POST to GET. For more information, please refer to the library docs.

All the best