UbidotsESP8266.h, get value bad request

I have a problem with getValue function. the first run return HTTP 200 but then always 400(bad request).
I’m using arduino uno and connect to ESP8266 12F via softwareSerial pin 2,3. Using the sample code but got this problem.

Serial debug
Response of ESP8266:
AT+CIPSEND

OK

Response of ESP8266:
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 03 Oct 2016 08:59:06 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: GET, POST, HEAD, OPTIONS

148
{“count”: 15, “next”: “http://things.ubidots.com/api/v1.6/variables/57e8de5b76254216a82a995e/values?page=2&page_size=1”, “previous”: null, “results”: [{“url”: “http://things.ubidots.com/api/v1.6/values/57f2041f76254243baa24719”, “value”: 1.0, “timestamp”: 1475478559115, “context”: {}, “created_at”: “2016-10-03T07:09:19.115”}]}
0

Response of ESP8266:
HTTP/1.1 400 Bad Request
Server: nginx
Date: Mon, 03 Oct 2016 08:59:17 GMT
Content-Type: text/html
Content-Length: 166
Connection: close

400 Bad Request

400 Bad Request


nginx

clearin data
Response of ESP8266:
HTTP/1.1 400 Bad Request
Server: nginx
Date: Mon, 03 Oct 2016 08:59:20 GMT
Content-Type: text/html
Content-Length: 166
Connection: close

400 Bad Request

400 Bad Request


nginx

Can you help me?
version of ESP from AT+GMR
AT version:1.3.0.0(Jul 14 2016 18:54:01)
SDK version:2.0.0(656edbf)

Arduino IDE version : 1.6.9
Thank you.

@kutarte Then, it works only in the first time?

Best regards,
Metavix

@Metavix, Yes. Works only in the first time.
i try to change the button state in my dashboard but always bad request.
What should i do?

Best Regards,
Kutarte

@kutarte Paste here your code please. I will help you with that

Best regards,
Metavix

Hi @Metavix,

#include <UbidotsESP8266.h>
#include <SoftwareSerial.h> 

#define SSID "TCS 1"
#define PASS "P@ssvv0rd"

#define TOKEN "B80RLEzYYE8jzRpECKjqTf9l------"
#define ID "57e8de5b76254216a8------"

Ubidots client(TOKEN);

void setup() {
  Serial.begin(9600);
  client.wifiConnection(SSID,PASS);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
}

void loop() {
  float value;
  value = client.getValue(ID);
  Serial.print("value : ");
  Serial.println(value);
  if(value > 0){
    digitalWrite(4,LOW);
  }
  else digitalWrite(4,HIGH);
  
} 

Best Regards,
Kutarte

Hi @Metavix,

Should I replace the ESP8266 firmware with the old version?
I had already upgraded its firmware to the latest version
Do you have any recommendations for the firmware version that work properly?

Best Regards,
Kutarte

@kutarte yeah it a good idea to try, i have a ESP with the old version and it works fine

By the way is much better to find the problem with the new firmware and try to solve it
Best regards,
Metavix

@Metavix, so what is your firmware version?
I don’t know how to find the problem now.
Do you have any library with MQTT protocol for ubidots? but using ESP8266 as a bridge/shield for arduino uno R3 via serial.

Best Regards,
Kutarte

I strongly recommend MQTT and not GET. You can use the PubSubClient library, works like a charm with Ubidots.

#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#define WIFISSID "IOT"
#define PASSWORD "SM1OT2016"
#define TOPIC1 "/v1.6/devices/motor/relay/lv"
#define TOPIC2 "/v1.6/devices/motor/temp"
#define TOKEN "xxxx"
#define PIN 12

int a;
const int B = 4275;                 // B value of the thermistor
const int R0 = 100000;            // R0 = 100k
const int pinTempSensor = A0;     // Grove - Temperature Sensor connect to A5
char mqttBroker[] = "things.ubidots.com";
char payload[100];

ESP8266WiFiMulti WiFiMulti;
WiFiClient c;
PubSubClient client(c);


void callback(char* topic, byte* payload, unsigned int length) {
    char p[length + 1];
    memcpy(p, payload, length);
    p[length] = NULL;
    String message(p);
    if (message == "0") {
      digitalWrite(PIN, LOW);
    } else {
      digitalWrite(PIN, HIGH);
    }
    Serial.write(payload, length);
    Serial.println(topic);
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.println("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("linkit-one", TOKEN,"")) {
      Serial.println("connected");
      client.subscribe(TOPIC1);
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 2 seconds");
      // Wait 2 seconds before retrying
      delay(2000);
    }
  }
}

void setup() {

    pinMode(PIN, OUTPUT);

    Serial.begin(115200);
    delay(10);

    // We start by connecting to a WiFi network
    WiFiMulti.addAP(WIFISSID, PASSWORD);

    Serial.println();
    Serial.println();
    Serial.print("Wait for WiFi... ");

    while(WiFiMulti.run() != WL_CONNECTED) {
        Serial.print(".");
        delay(500);
    }

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    client.setServer(mqttBroker, 1883);
    client.setCallback(callback);
}


void loop() {
    if (!client.connected()) {
      reconnect();
    }
    a = analogRead(pinTempSensor );
    float R = 1023.0/((float)a)-1.0;
    R = 100000.0*R;
    float temperature = 1.0/(log(R/100000.0)/B+1/298.15)-273.15;//convert to temperature via datasheet ;
    sprintf(payload,"%s%d.%02d%s", "{\"value\":", (int)temperature, (int)(temperature*100)%100,"}");
    Serial.println(payload);
    client.loop();
    client.publish(TOPIC2, payload);
    memset(payload, 0, sizeof(payload)); 

    delay(1000);
}

Hi @hackmed,
Thank you for your recommendation
is that program for ESP8266 standalone or as a additional modul for arduino uno?

Best Regards,
Kutarte

This one was tested with a NodeMCU board (standalone ESP), good luck!

I See @hackmed.
For some reason i need the ESP8266 as a bridge. Thank you by the way, I’ll try it after my problem solve (As a bridge).

Best Regards,
Kutarte

@kutarte i used this one http://www.electrodragon.com/w/ESP8266_AT_Commands, the clasic version

Best regards,
Metavix

Thank you @Metavix, I will try that version. But I still hope u can solve the problem on new version of firmware ESP8266.
I used this version http://bbs.espressif.com/viewtopic.php?f=46&t=2451,
and flashing with this parameter

yeah @kutarte, i am testing that version too, in this moment i find that the firmware of espressif has a lot of noise with SoftwareSerial library of Arduino. Now im using other libraries of Serial to reduce that noise. I think that today i will post the new version of the library, that will work.

Best regards,
Metavix

Thank you so much @Metavix, I’m waiting for that fix version of library.

Best Regards,
Kutarte

@Metavix, I’ve try the old version that you gave to me

AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04

But I still have the same problem. Are you using ESP-12 like me or the other type of ESP?

Best Regards,
Kutarte

@kutarte im using the same of you, could you try to put an pull down resistor, it may reduce the noise.

In this moment im trying with AltSoftwareSerial lib, with the example of 2 serial ports of that library.

Best regards,
Metavix

Where I should put the pull down? rx & tx?
Thank you @Metavix

Best Regards,
Kutarte

RX of the Arduino. You might use a example from the web.

Best regards,
Metavix