ESP8266 does not receive data from web (HTTP post method)
Posted: Thu May 16, 2019 8:09 am
Hi everyone,
i'm setting up, for training purposes, a system able to send/receive data over WiFi.
It is made of:
PC(Windows) --- ADSL --- ESP8266
Expected behaviour and outcomes are as follows:
ESP8266 tries to connect to Wifi: This works fine
ESP8266 fetches temperature/humidity data and sends them to PC: This works fine
From VB.net i try to send data to ESP8266 (POST): THIS FAILS
Application on PC is below. Instruction in bold is the one where the following error arises
("... Impossibile stabilire la connessione. Rifiuto persistente del computer di destinazione 192.168.1.3:80..")
Sub postaHTTP(ByVal azione As Integer, ByVal sensore As Integer, ByVal oste As String, ByVal porta As String, ByVal defo As String)
Dim s As HttpWebRequest
Dim enc As UTF8Encoding
s = HttpWebRequest.Create(defo + oste + ":" + porta)
enc = New System.Text.UTF8Encoding()
Dim postdata As String
Dim postdatabytes As Byte()
postdata = "sensore" + CStr(sensore) + ":" + CStr(azione) '"sensore0:0"
postdatabytes = enc.GetBytes(postdata)
s.Method = "POST"
s.ContentType = "application/x-www-form-urlencoded"
s.ContentLength = postdatabytes.Length
Dim posta As Stream = s.GetRequestStream()
posta.Write(postdatabytes, 0, postdatabytes.Length)
posta.Close()
MsgBox("Done", vbOKOnly, "Data sent")
End Sub
This is the piece of code in ESP8266 written/compile/loaded by means of ARDUINO IDE
boolean StartWiFi()
{
Serial.println(WiFi.localIP());
WiFi.disconnect();
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid, password);
Serial.println(ssid);
Serial.println(password);
while (WiFi.status() != WL_CONNECTED && WiFiCounter < 30) {
delay(dilei_uaifai);
WiFiCounter++;
Serial.print("*");
}
if (WiFiCounter < 30) {
return true;
} else {
return false;
}
delay(dilei_uaifai);
}
If i try to POST data to other destinations (i.e. 192.168.1.1or BBC.CO.UK) then it works.
Can anyone help ?
Thanks in advance
Fausto
i'm setting up, for training purposes, a system able to send/receive data over WiFi.
It is made of:
PC(Windows) --- ADSL --- ESP8266
Expected behaviour and outcomes are as follows:
ESP8266 tries to connect to Wifi: This works fine
ESP8266 fetches temperature/humidity data and sends them to PC: This works fine
From VB.net i try to send data to ESP8266 (POST): THIS FAILS
Application on PC is below. Instruction in bold is the one where the following error arises
("... Impossibile stabilire la connessione. Rifiuto persistente del computer di destinazione 192.168.1.3:80..")
Sub postaHTTP(ByVal azione As Integer, ByVal sensore As Integer, ByVal oste As String, ByVal porta As String, ByVal defo As String)
Dim s As HttpWebRequest
Dim enc As UTF8Encoding
s = HttpWebRequest.Create(defo + oste + ":" + porta)
enc = New System.Text.UTF8Encoding()
Dim postdata As String
Dim postdatabytes As Byte()
postdata = "sensore" + CStr(sensore) + ":" + CStr(azione) '"sensore0:0"
postdatabytes = enc.GetBytes(postdata)
s.Method = "POST"
s.ContentType = "application/x-www-form-urlencoded"
s.ContentLength = postdatabytes.Length
Dim posta As Stream = s.GetRequestStream()
posta.Write(postdatabytes, 0, postdatabytes.Length)
posta.Close()
MsgBox("Done", vbOKOnly, "Data sent")
End Sub
This is the piece of code in ESP8266 written/compile/loaded by means of ARDUINO IDE
boolean StartWiFi()
{
Serial.println(WiFi.localIP());
WiFi.disconnect();
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid, password);
Serial.println(ssid);
Serial.println(password);
while (WiFi.status() != WL_CONNECTED && WiFiCounter < 30) {
delay(dilei_uaifai);
WiFiCounter++;
Serial.print("*");
}
if (WiFiCounter < 30) {
return true;
} else {
return false;
}
delay(dilei_uaifai);
}
If i try to POST data to other destinations (i.e. 192.168.1.1or BBC.CO.UK) then it works.
Can anyone help ?
Thanks in advance
Fausto