1 Replies - 296 Views - Last Post: 15 February 2019 - 02:07 AM Rate Topic: -----

#1 omaromoh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-February 19

Node MCU with Dweet problem

Posted 14 February 2019 - 11:59 AM

This code is aiming to post a message to
Dweet but the output is unfortunately is
..WiFi connected!
IP address:
192.168.43.88
Setup ready
Sending dweet to dweet.io/follow/omar554
connection 1

closing connection
Which means that there is no data send to dweet as it closes before posting it on server



#include <ESP8266HTTPClient.h>


#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 = "Tedata2017";
//const char* password = "10009000*" ;
const char* ssid = "Omar";
const char* password = "11112222" ;
WiFiClient client;






//const char* key="omar2009";
String thingName = "omar554";
String hi = "I";
void setup() {
  // put your setup code here, to run once:

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

  pinMode(5, OUTPUT);
  //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() {
  WiFiClient client;
  String  dweetHttpGet = "GET/dweet/for/";
  dweetHttpGet = dweetHttpGet + String(thingName) + "?";
  dweetHttpGet = dweetHttpGet + String(hi) ;



  dweetHttpGet = dweetHttpGet + " HTTP/1.0\r\n" +
                 "Host: " +
                 host +
                 "\r\n" +
                 "Connection: close\r\n\r\n";
 
  //String url = "/dweet/for/";
  //  url += thingName;
  //  url += "?";
  //  url += "hi=";
  //  url += hi;
  //
  //
  //  Serial.print("Requesting URL: ");
  //  Serial.println(url);
  //
  //  // This will send the request to the server
  //  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
  //               "Host: " + host + "\r\n" +
  //               "Connection: close\r\n\r\n");



 // delay(10);
  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;
  }
  else {
    Serial.println("connection 1");

  }
  getDweetString();
  client.print(getDweetString());
  delay(10); //wait...
  while (client.available()) {
digitalWrite(5, HIGH);
    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();


  sendDweet(); //send data to dweet.io
  delay(2000);

}

I know that it is not a python code but this is the nearest section to my topic thanks for your time

Is This A Good Question/Topic? 0
  • +

Replies To: Node MCU with Dweet problem

#2 andrewsw   User is online

  • Stealth IT
  • member icon

Reputation: 6739
  • View blog
  • Posts: 27,749
  • Joined: 12-December 12

Re: Node MCU with Dweet problem

Posted 15 February 2019 - 02:07 AM

Moved to Other Languages forum. It is a C-type language... but it definitely ain't Python.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1