The use of the ESP8266 in the world of IoT

User avatar
By salmanali11053
#51835 Hey Guys,

I am working on a project in which I need to send one SMS if the Input pin is active(logic 1). I have to use PLIVO for sending sms and that sms can be sent by doing HTTP POST on the given URL by the plivo.

https://www.plivo.com/docs/api/message/

I am able to send HTTP POST on servers like thingspeak.com, experttexting.com and some http test servers but not on PLIVO Server.
I am able to send HTTP POST on PLIVO from web clients like POSTMAN, POSTER and HTTPRequester but not from the ESP8266 module.

Here is the raw transaction log from POSTMAN for successful SMS Sent.

Code: Select allPOST /v1/Account/MYAUTHID/Message/ HTTP/1.1
Host: api.plivo.com
Content-Type: application/json
Authorization: Basic TUFaSkRITldaSFlUS1dNVFZIWU06TXpSaU1XWm1OVGxrTmpGaE9XTmhOelJpWTJRMU5EaGlaR0ZqWVRKag==
Cache-Control: no-cache
Postman-Token: 02b0f9b7-234a-bc21-42c4-eb66c579a99d

{
  "src" : "+13303623231",
  "dst" : "+17133028183",
  "text" : "Hi from PLIVO"
}


This is a raw transaction log from HTTPRequester..
Code: Select allPOST https://api.plivo.com/v1/Account/MYAUTHID/Message/
Authorization: Basic
Content-Type: application/json
Username: MYUSERNAME
{
  "src" : "+13303623231",
  "dst" : "+17133028183",
  "text" : "Hi from PLIVO"
}


This is how I am posting from my ESP8266..

After connecting to the WiFi router..

Code: Select allconst char * host = "api.plivo.com";

void loop(void)
{
  /* Check if module is connected to the Server */
  if (client.connect(host, 80))
  {
         Serial.print("Connected to ");
         Serial.println(host);

        SendSMS();
        CheckServerResponse();
  }
}

void SendSMS(void)
{   
    String body = "{\n\"src\" : \"+13303623231\",\n\"dst\" : \"+17133028183\",\n\"text\" : \"Input 1 Triggered,   Alert from Salman via PLIVO on 31/07/2016\"\n}";
 
     client.print("POST https://api.plivo.com/v1/Account/MYAUTID/Message/");
     client.print("Authorization: Basic\n");
     client.print("Content-Type: application/json\n");
     client.print("Username: MYAUTHID\n");
     client.print("\n");
     client.print(body);
}

void CheckServerResponse(void)
{
  Serial.println("Server Response....");
 
  /* Read all the lines of the reply from server and print them to Serial */
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
}



I am not getting any response from the server. Am I missing something? Please help guys..
User avatar
By martinayotte
#51851 Few thing I see :
You are using unsecured HTTP client, while it seems that PLIVO is using a secured "https".
That can become a big issue.
But if PLIVO allows using unsecured request, like your POSTMAN example seems to details, then you can try to remove the URL portion in your POST, code would be like :
Code: Select allclient.print("POST /v1/Account/MYAUTID/Message/");

But, you will also need to add proper token like your POSTMAN example have :
Code: Select allclient.print("Authorization: Basic TUFaSkRITldaSFlUS1dNVFZIWU06TXpSaU1XWm1OVGxrTmpGaE9XTmhOelJpWTJRMU5EaGlaR0ZqWVRKag==");

In other words, make sure the request is identical to the one send by POSTMAN.
User avatar
By salmanali11053
#51883
martinayotte wrote:Few thing I see :
You are using unsecured HTTP client, while it seems that PLIVO is using a secured "https".
That can become a big issue.
But if PLIVO allows using unsecured request, like your POSTMAN example seems to details, then you can try to remove the URL portion in your POST, code would be like :
Code: Select allclient.print("POST /v1/Account/MYAUTID/Message/");

But, you will also need to add proper token like your POSTMAN example have :
Code: Select allclient.print("Authorization: Basic TUFaSkRITldaSFlUS1dNVFZIWU06TXpSaU1XWm1OVGxrTmpGaE9XTmhOelJpWTJRMU5EaGlaR0ZqWVRKag==");

In other words, make sure the request is identical to the one send by POSTMAN.


Hey I've tried by sending the String similar to POSTMAN log too, but no response from the server :(
User avatar
By bbx10node
#51899
Code: Select all     client.print("POST https://api.plivo.com/v1/Account/MYAUTID/Message/");
     client.print("Authorization: Basic\n");


The first line does not end with newline.

If adding a newline does not work, I would start capturing packets using tcpdump or wireshark to see what is really going on. I use a Linux firewall so it is possible to capture packets going to/from the Internet. I do know how you can do this using a regular WiFi router.