Ubidots Community

[SOLVED] ESP-01 and arduino uno

Hi, I am Jashwa. I was working on arduino and esp-01 module to post some data to my variables. I am using the Fixed IP to connect using the TCP protocol and the port i am using is 443 to secure transfer. No matter what i do I am not able to get data into my variable. Please take a look and suggests an edit.

This is my code as of now and I am not using any libraries

#include<SoftwareSerial.h>
SoftwareSerial a(10,11);
String ssid="Honor 8 Pro";    // Wifi network SSID
String pass = "mummy007";
char payload[200];
  char str_val_1[30];
  char const * VARIABLE_LABEL_1 = "b";
  
void showResponse(int waitTime){
    long t=millis();
    char c;
    while (t+waitTime>millis()){
      if (a.available()){
        c=a.read();
        Serial.print(c);
      }
    }                 
}
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  a.begin(115200);
}

void loop() {
    float sensor_value_1 = random(0, 1000)*1.0;

  /*---- Transforms the values of the sensors to char type -----*/

  /* 4 is mininum width, 2 is precision; float value is copied onto str_val*/
  dtostrf(sensor_value_1, 4, 2, str_val_1);

  // Important: Avoid to send a very long char as it is very memory space costly, send small char arrays
  sprintf(payload, "{\"");
  sprintf(payload, "%s%s\":{\"value\":%s}", payload, VARIABLE_LABEL_1, str_val_1);
  sprintf(payload, "%s}", payload);
  
  //Serial.println(payload);
    int contentLength = strlen(payload);
    a.println("AT+RST\r\n");   // set esp8266 as client
    showResponse(10000);
    a.println("AT+CWMODE=3\r\n");   // set esp8266 as client
    showResponse(10000);
    a.println("AT+CWJAP=\""+ssid+"\",\""+pass+"\"\r\n");  // set your home router SSID and password
    showResponse(10000);
    a.println("AT+CIPMODE=0\r\n");
    showResponse(10000);
    a.println("AT+CIPMUX=0\r\n");
    showResponse(10000);
    String cmd = "AT+CIPSTART=\"TCP\",\"";                  // TCP connection
    cmd += "169.55.61.243";                               // api.thingspeak.com
    cmd += "\",443\r\n";
    a.println(cmd);
    showResponse(10000);
    
    String getStr = "POST /api/v1.6/devices/a HTTP/1.1\r\nHost: things.ubidots.com\r\nUser-Agent: ESP8266/1.0\r\nX-Auth-Token: BBFF-rV13gArzJADwfGmU9wzeTVi0M1VCFQ\r\nConnection: close\r\nContent-Type: application/json\r\nContent-Length: ";    
    getStr += contentLength;
    getStr += "\r\n\r\n";
    getStr += payload;
    getStr += "\r\n";
    cmd = "AT+CIPSEND=";
    cmd += String(getStr.length());
    a.println(cmd);
    showResponse(10000);
    a.println(getStr);
    showResponse(10000);
}

When I remove the Content length and the payload there is no 400 Bad request but Send OK messge
But when I try to send the whole command with Content length and payload I am getting this error

=========================================================

This is my response

AV+CIPSTART="VCP","169.55'61.243",443CC⸮CC!⸮]⸮^⸮⸮ryj
COONECT

OK
	AT+CIPSEND=21c


OK
> 

busy s../

Recv 213 bytes

SF⸮D OK

+IPD,409:HTTP/1.1 400 Bad Requesv
Server: ng⸮nx
Date: Qat, 01 De8 et
n
:k⸮

ieB⸮Ձ͕⸮Q<e⸮⸮⸮⸮ɥ⸮
⸮⸮⢂⸮⸮⸮⸮⸮
=================================================

Hi AGAIN, NEVER MIND I SOLVED IT I CHANGED THE FIXED IP TO DNS USING TCP and CONNECTED TO PORT 80 WITH THE SAME X-AUTH-TOKEN AUTHENTICATION. THANKS IN ADVANCE FOR THE REPLY

Greetings, my two cents, if you are trying to use HTTPS instead of HTTP, you must add the TLS certificate to your firmware and to include a certificate validation routine, that was the reason of the failure in your first attemtp.

All the best