3

I have implemented a basic light controller for Livolo light switches using an ESP8266 running a web server and a library i found for the livolo switches that uses an RF433 transmitter.

i dont have any problem with the code as such.. (and i can post it if required) the web server listens for a request and then calls the function to send the rf433 signal (which takes around 2 seconds - as the livolo protocol is basically blast the same thing 100 times).

the problem is the web server/entire arduino/esp8266 'blocks' whilst it is sending the RF signal - for up to 2 seconds.

if i just have the web server listening, and say just writing out a string to the serial debugger, its lightning fast.. can hit it multipole times a second reposnsively.

normally this is OK, but the home automation system that sends the web requests I am working with doesn't wait round.. so if its sending say 10 requests in a row (turn off all lights), my little web server basically cant keep up as the esp8266 is busy doing the RF broadcast, it gets behind and then the system sending the requets stars getting socket errors.. i cant change the system that sends unfortunately.

i tried implementing as basic FIFO queue but essentially the same problem happens. I am wondering if it is better to implement two arudino's (esp8266) with a bus like i2c in between? the one web server can take requests and put them in to a queue, and the other one can lazily read the queue and do the RF sending...

i was wondering if any one has a suggestion on a) is this the right way to go? b) what bus should i use between hardware.. c) any example of a remote queue reading implementation?

any thoughts greatly appreciated.. i can share code re the web server etc if required but its pretty basic arudino esp8266 web server implementation, and thats not really where i am stuck.. i guess i am more interested in a code example that shows one piece of hardware reading the queue implemented on another if that makes sense?

Paul O'Brien
  • 171
  • 1
  • 11
  • you might be able to use a gpio breakout board to handle the rf sending in a way that didn't busy the esp, but a 2nd esp (especially an 01) would be cheaper and would work very well: a "dual core" design. – dandavis Oct 25 '16 at 21:06
  • thanks for suggestion.. yes, had started down 2 chips over i2c. – Paul O'Brien Feb 17 '17 at 06:45

2 Answers2

3

The ESPAsyncWebServer was built exactly for this purpose - It handles all web requests asynchronously, and very fast. I can query my local units (As well as the countless production units) 10-20 times a second without issue for days and days. I for example query AC power data in my main loop, and expose the stored data via a web server. The query for data can take as long as it wants via the UART (Typically ~500ms), but, the web requests will always be served as soon as they come in

Have the main loop run the RF logic, and store the data as a global (Or equivalent), and let the web server simply send the stored value to the client

Dawn Minion
  • 905
  • 5
  • 12
1

I can think of two solutions

1) Interupts

Interupts allow Arduino to run blocking code without stopping the program. Would advice checking them out. I am concerned however that the arduino may not have enough processing power and memory to be able to handle both managing the server and executing commands

2) Two Devices (with interupts!)

Connect two Arduinos over an i2c bus. The first would listen for incoming web requests, then communicate with the second to execute a given command (over the i2c bus). The second would use interupts to listen to incoming commands. The interupt would add each command to a queue, and the main loop of the program would execute the most recent command.

jstm
  • 420
  • 4
  • 14
  • 1
    thanks, I started going down the 2 esp8266 using i2c, one master, and other slave, then learnt the esp8266 couldn't be a slave.. so used an Arduino nano as slave, then struggles passing data between two.. I think I will try the ESPAsyncWebServer suggested below, if that works, problem solved on one chip.. if not, looks like either 2 chips with i2c or wait for the Esp32 which will solve all these problems :) – Paul O'Brien Feb 17 '17 at 06:44