Creating subloops in Blynk code, ESP8266



Hello Guys,

I am fairly new to ESP and Blynk, but not new to Arduino, and I have a serious problem in implementing my project. I am using the Blynk server and ESP8266 12E board.
The ESP based module has to communicate with some other borads over simple 433MHz transciever, the cheep chinese type.
I have found out that ~ 1k bps is not a problem for my Atmeg328 based boards, but I can’t find a way to implement it on the ESP, I am getting over 3ms looptime at idle, and it can go up to 300ms when receiving data from the web.
To not mess up my whole structure, I would need to run my output handling routine in every 50-100us when transmitting, and every 1ms when receiving. Both is rather simple code, as I said, 16MHz Atmega is fine with maintaining the 1kbps bitrate.

I am totally out of ideas by now, do you have any ideas except for changing the wireless module?


The problem is no doubt caused by the Blink routine that has to constantly communicate with the Blynk server to do the Blynk “magic”.

The normal way to get all your boards talking to each other would be to use ESP boards that are are all connected to your Wi-Fi system and each talk separately to the Blynk server. Each device would have it’s own Blynk Auth code, but be part of the same Blynk Project. The data from the server can then be accessed by one ‘master’ device using Bridge to link the separate Auth codes together.

An alternative is to still have each device connected to your Wi-Fi but use MQTT messaging to transfer data between devices. This can either be by using an ESP as the MQTT server, or using a Raspberry Pi - in which case you’d go down the Node-Red route to manage the flow of data between the ESP devices and Blynk.

I’m guessing that you don’t want to go down that route, either because you’d have to replace multiple devices or because some of those devices are out of Wi-Fi range (or both)?

In reality, devices like the Wemos D1 Mini are dirt cheap and very easy to use, but they still need to be able to see your Wi-Fi network.

If you tell us a bit more about what your system does, and what sort of data is sent over your 433MHz network then we might be able to offer a few more suggestions.



You are right, I agree that the simplest solution would be to have an esp at every module. The problem in my application this would mean 6 modules at start, optionally extended to 15. This would most likely overload my wifi network, that I definitely don’t want to do. The range would not necessarily be a problem.
The message is rather simple, sending 16 bits, 1200us each bit, changing the high time. Sort of PWM coding, each pulse is a bit.
I have been thinking about the possibility to add another Arduino pro mini to deal with the 433 communication, and connect it to the ESP via I2C or uart, so I don’t have to worry about messing with interrupts at the Blynk code. Considering the extra ADC and GPIO capacity, this might be a very reasonable idea.
What do you think?


That seems unlikely. I have 12 devices connected to my network at the moment, all sending MQTT data at regular intervals, and don’t have any issues.

Yes, that’s something I considered when replying to your post, it could be a good solution.

I’m still intrigued about this, and wondering if there’s a better solution with the tools available now. Do you want to say more? and say where Blynk would come into the equation fort you?



My internet provider also provides a router, and back at the uni we used the same one with the roommates. It usually started to fail at about 8 devices. I know it is garbage, but I don’t want to invest in a new router yet. Also, when the systems has 15 modules, I still have another 5 device connected (laptops, smartphones, printer).

I am sure there is a better solution, but this seemed to be the most cost effective way from hardware point of view. I have also been trying to use software serial, without success.
Sending is done by setting the output pin high at the beginning of each bit, and pulling down after either 300 or 900us. There is a 150us tolerance on receiver side, this is why it is sufficient to run this code at every ~50-100us. No interrupts used for this one, I am sure it could have been solved using timers on Atmega, but I am also sure that would not work on ESP. I’d like to keep my code universal and simple.
Receiving uses interrupts, one saves the rising time in microsec, one saves the falling time in microsec. This is translated to 1 or 0 if the code is called in the 1200us window, after the falling edge.
Each module is either a sensor, or controls a skylight motor, a power socket, etc. The system has to work in standalone mode, and I want to solve remote access with blynk.


In the mean time I have managed to establish i2c communication between my pro mini and the ESP board, so I think this solution will be the winner. Thank you for the support!