I've been working on this project, which consists in using a web page to control RPi's GPIOs and read sensor data via WebIOPI. Everything worked fine, at this point the project is very simple and the documentation on WebIOPi website really helped. Also, if anyone is having trouble with this, I recommend this tutorial. But I decided to raise the complexity level by doing the exact same thing, except controlling various ESP-01s connected to the server as clients. These ESP-01s have been updated with NodeMCU firmware, in order to be programmed directly and not only used as Wi-Fi modules for some other microcontroller. Also, they can be programmed straight from the Arduino IDE, which really helps.
The thing is: I have no experience at all working with HTTP protocols. There are several examples for both server and client applications on the ESP8266 side, but I can't figure out what to do on the RPi side. I've already been able to connect the ESP-01 to the server on the Pi, but I can't really exchange information between them.(Here is the code that does the connection on the client side, in case anyone asks)
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#define LED0 2
char* ssid = "SSID";
char* password = "PASSWORD";
int ESPServerPort = 8000;
IPAddress ESPServer(192,168,0,133);
WiFiClient client;
void setup() {
Serial.begin(115200);
pinMode(LED0, OUTPUT);
Serial.println("\nSetting I/O Pin Modes ... Done\n");
if(WiFi.status() == WL_CONNECTED){
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
delay(50);
}
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("!--- Connecting To " + WiFi.SSID() + " ---!");
CheckWiFiConnectivity();
digitalWrite(LED0, LOW);
Serial.println("!-- Client Device Connected --!\n");
Serial.println("Connected To : " + String(WiFi.SSID()));
Serial.println("Signal Strenght : " + String(WiFi.RSSI()) + " dBm");
Serial.print ("Server IP Address : ");
Serial.println(ESPServer);
Serial.print ("Server Port Num : ");
Serial.println(ESPServerPort);
Serial.print ("Device MC Address : ");
Serial.println(String(WiFi.macAddress()));
Serial.print ("Device IP Address : ");
Serial.println(WiFi.localIP());
Serial.print ("\n\n");
ESPRequest();
}
void loop(){
}
void CheckWiFiConnectivity(){
while(WiFi.status() != WL_CONNECTED){
for(int i=0; i < 10; i++){
digitalWrite(LED0, !HIGH);
delay(250);
digitalWrite(LED0, !LOW);
delay(250);
Serial.print(".");
}
Serial.println("");
}
}
void ESPRequest(){
client.stop();
Serial.println("!---Connecting to server---!");
client.connect(ESPServer, ESPServerPort);
if(client.connected()){
Serial.println ("<CONNECTED>\n");
client.println ("<CONNECTED>");
}
}
I'm not sure if I need to tap into the WebIOPi code files, the ones that do the HTTP heavy-lifting, or if simple changes on my html/javascript code would do the trick. Well... How can I do this?
Help a newbie out guys. Thanks in advance!