Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Node mcu is not working properly with dweet

Status
Not open for further replies.

omar0

Newbie level 1
Newbie level 1
Joined
Feb 14, 2019
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
30
I amm working with nodemcu with dweet as a beginner to send a message to the dweet after I upload the code the result is a pannel showing this message:
Connecting to Omar...
..WiFi connected!
IP address:
192.168.43.88
Setup ready
Sending dweet to dweet.io/follow/omar67
connection 1

closing connection

The following is the code that I wrote to implement this small project


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#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" ;
//const char* key="omar2009";
String thingName = "omar67";
String hi = "How are you";
void setup() {
  // put your setup code here, to run once:
 
  Serial.begin(115200);
  delay(10);
  //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 = "POST /dweet/for/";
  dweetHttpGet = dweetHttpGet + String(thingName) + "?";
  dweetHttpGet = dweetHttpGet + String(hi) ;
  dweetHttpGet = dweetHttpGet + " HTTP/1.1\r\n" +
                 "Host: " +
                 host +
                 "\r\n" +
                 "Connection: close\r\n\r\n";
  dweetHttpGet = dweetHttpGet + " HTTP/1.1\r\n" + "Host: " + host + "\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()) {
 
    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);
 
}

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top