I am working on nodemcu ( I would like to send only a hi message to dweet.io) the problem is when it sends to dweet it closes the connection at once the code is down below:
#include <ESP8266WiFi.h>
//const int ledpin1=5;
//const int ledpin2=4;
//const int ledpin3=15;
//const int input1=13;
//const int input2=14;
//const int input3=12;
//int counter=0;
const char* host = "dweet.io";
//// WiFi parameters
const char* ssid = "Omar";
const char* password ="11112222" ;
//const char* key="omar2009";
String thingName="omar11";
String hi="HELLO World";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//Connect to WiFi Network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println("...");
WiFi.begin(ssid, password);
int retries = 0;
while ((WiFi.status() != WL_CONNECTED) && (retries < 15)){
retries++;
delay(500);
Serial.print(".");
}
if(retries>14){
Serial.println(F("WiFi conenction FAILED"));
}
if (WiFi.status() == WL_CONNECTED){
Serial.println(F("WiFi connected!"));
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
Serial.println(F("Setup ready"));
}
String getDweetString(){
String dweetHttpGet="GET /dweet/for/";
dweetHttpGet=dweetHttpGet+String(thingName);
dweetHttpGet=dweetHttpGet +"?HI" + "=" +String(hi);
dweetHttpGet=dweetHttpGet+" HTTP/1.1\r\n"+
"Host: " +
host +
"\r\n" +
"Connection: close\r\n\r\n";
return dweetHttpGet;//this is our freshly made http string request
}
void sendDweet(){
WiFiClient client;
const int httpPort = 80;
//connect to dweet.io
if (!client.connect(host, httpPort)){
Serial.println("connection failed");
return;
}
client.print(getDweetString());
delay(10); //wait...
while (client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print("Sending dweet to ");
Serial.print(host);
Serial.print("/follow/");
Serial.print(thingName);
Serial.println();
String hi="HELLO World";
sendDweet(); //send data to dweet.io
delay(2000);
}
The ouput is:
Connecting to Omar...
......WiFi connected!
IP address:
192.168.43.88
Setup ready
Sending dweet to dweet.io - Share your thing- like it ain't no thang.
closing connection
please could anybody help