OpenSprinkler › Forums › OpenSprinkler Unified Firmware › NodeMCU ESP8266 connecting to OS Pi – Fails with -1 response
- This topic has 1 reply, 1 voice, and was last updated 4 years, 5 months ago by wateru.
-
AuthorPosts
-
August 2, 2020 at 8:20 am #67682
wateruParticipantHi,
I am trying to connect to OS Pi from NodeMCU ESP8266 via the API. I have spent several days without success. Really appreciate anyone who can help me here.I recently purchased (within the last month) my OS Pi so have the latest firmware on OS Pi. I am using the following code to connect from ESP8266 to OS Pi and I only get a -1 error. My ESP8266 connects to ThingSpeak and posts data just fine. So, I know the ESP8266 is on the WiFi and able to communicate. Calling any other http site with the http.begin code returns the proper response with out errors. Also, using the GET method in Postman with the same exact URL “http://192.168.X.XX:8080/mp?pw=a6d82bced638de3def1e9bbb4983225c&pid=0&uwt=0” returns a 1 and 200 response – all good. So, I know the OS Pi details are correct for the URL. I just cannot get the ESP8266 to the URL and talk to OS Pi. Please help!! I even submitted a ticket, but was told this is my ESP8266 issue and the ticket was closed without contacting met. Anyone out there who successfully connected to OS Pi from NodeMCU? Really appreciate someone helping me. Thank you in advance.
#include <ESP8266WiFi.h> // Include the Wi-Fi library
#include <ESP8266HTTPClient.h>const char* ssid = “XXXXXXX”; // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = “XXXXXX”; // The password of the Wi-Fi networkconst char* host = “http://192.168.X.XX:8080/”;
const char* md5hash = “a6d82bced638de3def1e9bbb4983225c”;
int pid = 0;
int uwt = 0;void setup() {
Serial.begin(115200); // Start the Serial communication to send messages to the computer
delay(10);
Serial.println(“*****************************************************”);
Serial.println(“********** Program Start : Soil Moisture monitoring using ESP8266 and ThingSpeak IoT cloud”);
Serial.println(“Wait for WiFi… “);
Serial.print(“********** connecting to WIFI : “);
Serial.println(ssid);
WiFi.begin(ssid, password); // Connect to the networkint i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(500);
Serial.print(++i); Serial.print(“.”);
}Serial.println(‘\n’);
Serial.println(“Connection established!”);
Serial.print(“IP address:\t”);
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computerString url = “”;
url += host;
url += “/mp?pw=”;
url += md5hash;
url += “&pid=”;
url += pid;
url += “&uwt=”;
url += uwt;Serial.println(url);
HTTPClient http;
http.begin(host);
// start connection and send HTTP header
int httpResponseCode = http.GET();
Serial.print(httpResponseCode);// httpCode will be negative on error
if(httpResponseCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf(“[HTTP] GET… code:%d\n”, httpResponseCode);} else {
Serial.printf(“[HTTP] GET… failed%s\n”);
}http.end();
}}
void loop() {
}
This is the response I see in Serial Monitor:
3.4.5.6.7.Connection established!
IP address: 192.168.X.XX
http://192.168.X.XX:8080/mp?pw=a6d82bced638de3def1e9bbb4983225c&pid=0&uwt=0
-1[HTTP] GET… failedAugust 4, 2020 at 1:55 pm #67726
wateruParticipantMade more progress and found out the communication failure was due to network issue. Moved both the ESP8266 NodeMCU and the OS Pi to the base home LAN from the Eero network. That fixed it. Have not yet found out why being in the Eero network does not allow these two 2.4GHz devices to communicate with each other. At least I was able to get past the issue and have my sensor talk to the sprinkler and turn on the sprinklers using moisture data. The API works as advertised. Thought I would send in the follow-up in case others have similar issues.
-
AuthorPosts
- You must be logged in to reply to this topic.
OpenSprinkler › Forums › OpenSprinkler Unified Firmware › NodeMCU ESP8266 connecting to OS Pi – Fails with -1 response