-->
Page 1 of 1

Posting on dweet.io using AT Commands

PostPosted: Tue Jan 10, 2017 4:15 pm
by basit701
Hello Guys i have written a code to send data to Dweet.io using TCP connected (through AT Commands). The problem is that even by following the proper method, data sent does not appear on dweet website. Although i do receive this response from the ESP8266 when TCP request is sent.

AT+CIPSEND=098


OK
>
se
busy s...

Recv 98 bytes



busy s...

SEND OK

PS: I am using Tiva Launchpad TM4C123GXL. I have made functions Commandprintln and Commandprintln to send commands to ESP, while println just gives output to FTDI which is connected to PC.

CODE for Initialising ESP8266
Code: Select allchar StartModule()
{
  //reset and test if the module is ready ------------------------------------------------------------------------------------------------------
  bool module_responding =  false;
  bool connected_to_access_point = false;
  bool connected_to_dweet = false;
  int connection_attempts = 0;
  char cmd[100] = "AT+CWJAP=\"";
   char cmd1[100] = "";
  println("Starting module");
  while(!module_responding){
   
    Commandprintln("AT+RST");//reset module (works with both ESP-01 and ESP-03 module)

    if (wait_for_esp_response(5000, "ready")){ //watch out for the case of the r in ready - varies with ESP8266 firmware version
      println("Module is responding");
      module_responding = true;
    }
    else{
      println("Module not responding to reset");
      delay(1000);
    }
  }


  Commandprintln("AT+GMR");
  wait_for_esp_response(1000,OKrn);
 
  Commandprintln("AT+CWMODE=1");
  wait_for_esp_response(1000,OKrn);
 
  Commandprintln("AT+CIPMUX=0");
  wait_for_esp_response(1000,OKrn);
 
  println("Connecting to WiFi access point...");
Commandprintln("AT+CWQAP");
delay(100);
  strcat(cmd,SSID);
  strcat(cmd, "\",\"");
  strcat(cmd,PASS);
   strcat(cmd,"\"");
  println(cmd);
  Commandprintln(cmd);
  delay(5000);
   connected_to_access_point = wait_for_esp_response(9000,OKrn);
 
   if(!connected_to_access_point){
    println("Attempt to connect to access point failed. Restarting module.");
    return false;
  }
  else
  {
    println("CONNECTED TO ACCESS POINT");
  }
  //}

  println("Connecting to dweet...");
  while((!connected_to_dweet)&&(connection_attempts < MAX_SERVER_CONNECT_ATTEMPTS)){
  memset(cmd1,'\0',100);
      strcat(cmd1,"AT+CIPSTART=\"TCP\",\"");
      strcat(cmd1,URL);
      strcat(cmd1,"\",");
      strcat(cmd1,PORT);
      

   Commandprintln(cmd1);
    delay(1000);
      println(cmd1);
    connected_to_dweet = wait_for_esp_response(9000,OKrn);//this needs to change - look for  something in server response that indicates valid connection
    connection_attempts += 1;
    if (!connected_to_dweet)
    {
      println("Attempt to connect to dweet did not succeed");
    }
    else
    {
      println("CONNECTED TO DWEET");
    }
  }
  return connected_to_dweet;
}


CODE FOR sending request

Code: Select allvoid loop(void) {
 bool connected_to_dweet = false;
  int connection_attempts = 0;
  char cmd1[100] = "";
   //char dweet[200] = "";
   memset(sig_string,'\0',200);
         memset(temp,'\0',3);
  len = 80;
 
  //Special appraoch required for floating point value here.
                              //Have to use dtostrf instead of sprintf since sprintf doesn't
                              //support floats on Arduino.
  strcat(sig_string,"98"); //convert from character buffer array to string so
                                //white space can be cleared with .trim().
 
 
  len += strlen(sig_string);
 len+= strlen(sig_string);
  len += (sizeof(thing_name) - 1);//sizeof will return 11 for a 10 character thing name because of null terminator
                                  //so subtract 1
get_dec_str(temp,3,len);
  //form and send the HTTP POST message
  Commandprint("AT+CIPSEND=");
  Commandprintln(temp);
   println("AT+CIPSEND=");      
  if (!wait_for_esp_response(9000,"> ")){
    Commandprintln("AT+CIPCLOSE");
    println("send timeout - resetting wifi module");
    delay(2000);
    //StartModule();
      
      println("Connecting to dweet...");
              StartModule();
      delay(3000);
  }
 
  Commandprint("GET /dweet/for/"); 
  //Serial.print(F("GET /dweet/for/"));// both POST and GET work
  Commandprint(thing_name);
  Commandprint("?temperature=");
  Commandprint(sig_string);
  Commandprint("&humidity=");
  Commandprint(sig_string);
  Commandprint(" HTTP/1.1\r\n");
  Commandprint("Host: dweet.io\r\n");
  Commandprint("Connection: close\r\n");//in some cases connection needs to be closed after POST
 // Commandprint("Connection: keep-alive\r\n");//in this case we want to keep the connection alive
  Commandprint("\r\n");
 
  wait_for_esp_response(9000,"}}}\r\nOK");
 
  delay(2000);
 
  Ramp+=17;
  if(Ramp>99){
    Ramp=10;
  }
  Sig = 65*(2 * 3.142 * freq * 55 / 1000);

}


main function

Code: Select allint main(void)
{


    setUp();

   
    while(!StartModule()){
    delay(1000);
    println("***Calling StartModule Again***");
  }
   
    while(1){
    loop();

 
         println("YEAH MAN"); //dummy
         
         delay(1000);
      };
}