-->
Page 1 of 1

WeMoS andRaspberryPi

PostPosted: Fri Apr 27, 2018 5:18 am
by The_Novice
Hi, I am a newbie to WeMoS and esp8266. So, I created a PHP page that will read data sent from my wemos and store it in a database. I wrote the corresponding wemos (Arduino) code that will post data to the IP address of my raspberrypi . This is working fine.
Now I want to send data from raspberrypi to wemos. What I have is a text box. If the user enters 1, a light bulb switches on and if he enters 0 it switches off. I created the HTML and javascript codes for this and stored it in my Raspberry Pi. Now how would and in what format should I send this data to my wemos?
Thank You.

Re: WeMoS andRaspberryPi

PostPosted: Sat Apr 28, 2018 10:19 pm
by lapgoch
Just put your switch status 0 or 1 in a txt file eg status.txt on your RPI server.
In your wemos code use client.println("GET /RPIserverFilepath/status.txt");

Re: WeMoS andRaspberryPi

PostPosted: Sun Apr 29, 2018 1:58 pm
by btidey
Or use a Web Server on the Wemos
Code: Select allESP8266WebServer server(80);

Define a response mechanism to a url to the server in setup
Code: Select allserver.on("/switch", doSwitch);
doSwitch should now be a void function that will get called when say a GET is done to
Code: Select allhttp://ip/switch?state=1

This includes 0 or 1 'state' argument in the get and extract it in the doSwitch function and action it.

Code: Select allvoid doSwitch() {
   int state = server.arg("state").toInt();
   //do something with 'state to action switch
   server.send(200, "text/html", "switch done");
}