Blynk in ESP32

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Blynk in ESP32

#1 Post by FanM » 13 Sep 2021, 23:23

Hi there!
Guys, help me please to add blynk controller in ESP32 firmware.
Custom-sample.h renamed in Custom.h
in [env:normal_ESP32_4M316k] added build_flags -DUSE_CUSTOM_H
All useless. File custom.h is not compiled at all.
Please help!

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Blynk in ESP32

#2 Post by Ath » 14 Sep 2021, 08:56

You should compile the 'custom_ESP32_4M316k', that will use the Custom.h adaptions.

But your compile will fail, as the source code of that Blynk library will bork, telling you it can't compile for ESP32, that's why I said (in the other thread) it needs an update first, and that is a little more work then just a drop-in replacement...
/Ton (PayPal.me)

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#3 Post by FanM » 14 Sep 2021, 10:45

Custom-sample.h renamed in Custom.h
Used task [env:custom_ESP32_4M316k] in compilation.
Compiled OK, but custom.h is not compiled at all.
No errors.

Uncommented #define USE_CUSTOM_H in ESPEasy_common.h
A lot of not critical errors in compiling process, mostly about:
espeasy_common.h:7:0: warning: "USE_CUSTOM_H" redefined
#define USE_CUSTOM_H
custom.h not compiled in fact.

Uncommented C12 and C15 and get error, not compiled...

Yes, seems need to upgrade the blynk firmware, but i cannot do that, i am not programmer.
Last edited by FanM on 14 Sep 2021, 10:49, edited 1 time in total.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#4 Post by TD-er » 14 Sep 2021, 10:46

Make sure to rename the file to Custom.h, with a capital C.

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#5 Post by FanM » 14 Sep 2021, 10:53

Sorry, forgat to uncomment C12 and C15.
The error is:

Code: Select all

In file included from D:/_ESPEASY_/ESPEasy_ESP32_mega-20210802/source/src/_C015.ino:42:0:
lib/Blynk/src/BlynkSimpleEsp8266.h:15:2: error: #error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting.
 #error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting.
  ^
lib/Blynk/src/BlynkSimpleEsp8266.h:18:21: fatal error: version.h: No such file or directory

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#6 Post by FanM » 14 Sep 2021, 11:00

Firmware really works only with ESP8266. C15 contain only ESP8266 lib.
If change lib/Blynk/src/BlynkSimpleEsp8266.h on lib/Blynk/src/BlynkSimpleEsp32.h and upload the latest Blynk firmware that supports ESP32, then a new error:
_C015.ino:340:22: error: no matching function for call to 'BlynkWifi::config(const char*, void (&)(), IPAddress&, unsigned int&)'
Failed

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Blynk in ESP32

#7 Post by Ath » 14 Sep 2021, 11:16

That's where I stopped because of a lack of time...
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#8 Post by TD-er » 14 Sep 2021, 11:24

Maybe the updated library also supports ESP32 now?
See: https://github.com/letscontrolit/ESPEasy/issues/3776

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#9 Post by TD-er » 14 Sep 2021, 11:34

I'm now testing to see if we can build it on ESP32 using the updated library.

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#10 Post by FanM » 14 Sep 2021, 12:06

Library supports ESP32, but need to change C15. It was written for ESP8266

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#11 Post by TD-er » 14 Sep 2021, 12:08

See: https://github.com/letscontrolit/ESPEasy/pull/3783
This should build in ESP32
Still need to update to the newer library to support Blynk v2

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#12 Post by FanM » 14 Sep 2021, 15:54

I give up!
I took a new 1.0.1 blynk and copied in the lib folder.
Thet copied your new files from last update.

Code: Select all

In file included from lib/Blynk/src/BlynkSimpleEsp32.h:21:0,
                 from D:/_ESPEASY_/ESPEasy-844915618f60f74405f93b3e0d79034d83a48e90/src/_C015.ino:51:
lib/Blynk/src/Blynk/BlynkProtocol.h: In member function 'bool BlynkProtocol<Transp>::processInput()':
lib/Blynk/src/Blynk/BlynkProtocol.h:378:72: error: there are no arguments to 'BlynkWidgetWriteInternalPinUTC' that depend on a template parameter, so a declaration of 'BlynkWidgetWriteInternalPinUTC' must be available [-fpermissive]
         case BLYNK_INT_UTC:  BlynkWidgetWriteInternalPinUTC(req, param2);    break;
                                                                        ^
lib/Blynk/src/Blynk/BlynkProtocol.h:378:72: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
lib/Blynk/src/Blynk/BlynkProtocol.h:382:73: error: there are no arguments to 'BlynkWidgetWriteInternalPinMETA' that depend on a template parameter, so a declaration of 'BlynkWidgetWriteInternalPinMETA' must be available [-fpermissive]
         case BLYNK_INT_META: BlynkWidgetWriteInternalPinMETA(req, param2);   break;
                                                                         ^
lib/Blynk/src/Blynk/BlynkProtocol.h:383:72: error: there are no arguments to 'BlynkWidgetWriteInternalPinVFS' that depend on a template parameter, so a declaration of 'BlynkWidgetWriteInternalPinVFS' must be available [-fpermissive]
         case BLYNK_INT_VFS:  BlynkWidgetWriteInternalPinVFS(req, param2);    break;
                                                                        ^
lib/Blynk/src/Blynk/BlynkProtocol.h:384:72: error: there are no arguments to 'BlynkWidgetWriteInternalPinDBG' that depend on a template parameter, so a declaration of 'BlynkWidgetWriteInternalPinDBG' must be available [-fpermissive]
         case BLYNK_INT_DBG:  BlynkWidgetWriteInternalPinDBG(req, param2);    break;
                                                                        ^
In file included from D:/_ESPEASY_/ESPEasy-844915618f60f74405f93b3e0d79034d83a48e90/src/_C015.ino:51:0:
lib/Blynk/src/BlynkSimpleEsp32.h: In member function 'void BlynkWifi::config(const char*, void (*)(), const char*, uint16_t)':
lib/Blynk/src/BlynkSimpleEsp32.h:39:49: error: no matching function for call to 'BlynkWifi::begin(const char*&, void (*&)())'
         Base::begin(auth,handleInterruptCallback);
                                                 ^
In file included from lib/Blynk/src/BlynkSimpleEsp32.h:21:0,
                 from D:/_ESPEASY_/ESPEasy-844915618f60f74405f93b3e0d79034d83a48e90/src/_C015.ino:51:
lib/Blynk/src/Blynk/BlynkProtocol.h:111:10: note: candidate: void BlynkProtocol<Transp>::begin(const char*) [with Transp = BlynkArduinoClientGen<Client>]
     void begin(const char* auth) {
          ^
lib/Blynk/src/Blynk/BlynkProtocol.h:111:10: note:   candidate expects 1 argument, 2 provided
In file included from D:/_ESPEASY_/ESPEasy-844915618f60f74405f93b3e0d79034d83a48e90/src/_C015.ino:51:0:
lib/Blynk/src/BlynkSimpleEsp32.h: In member function 'void BlynkWifi::config(const char*, void (*)(), IPAddress, uint16_t)':
lib/Blynk/src/BlynkSimpleEsp32.h:48:49: error: no matching function for call to 'BlynkWifi::begin(const char*&, void (*&)())'
         Base::begin(auth,handleInterruptCallback);
                                                 ^
In file included from lib/Blynk/src/BlynkSimpleEsp32.h:21:0,
                 from D:/_ESPEASY_/ESPEasy-844915618f60f74405f93b3e0d79034d83a48e90/src/_C015.ino:51:
lib/Blynk/src/Blynk/BlynkProtocol.h:111:10: note: candidate: void BlynkProtocol<Transp>::begin(const char*) [with Transp = BlynkArduinoClientGen<Client>]
     void begin(const char* auth) {
          ^
lib/Blynk/src/Blynk/BlynkProtocol.h:111:10: note:   candidate expects 1 argument, 2 provided
D:/_ESPEASY_/ESPEasy-844915618f60f74405f93b3e0d79034d83a48e90/src/__Plugin.ino: In function 'void PluginInit()':
D:/_ESPEASY_/ESPEasy-844915618f60f74405f93b3e0d79034d83a48e90/src/__Plugin.ino:31:12: warning: unused variable 'x' [-Wunused-variable]
   uint32_t x = 0; // Used in ADDPLUGIN macro
            ^
In file included from lib/Blynk/src/BlynkSimpleEsp32.h:21:0,
                 from D:/_ESPEASY_/ESPEasy-844915618f60f74405f93b3e0d79034d83a48e90/src/_C015.ino:51:
lib/Blynk/src/Blynk/BlynkProtocol.h: In instantiation of 'bool BlynkProtocol<Transp>::processInput() [with Transp = BlynkArduinoClientGen<Client>]':
lib/Blynk/src/Blynk/BlynkProtocol.h:159:30:   required from 'bool BlynkProtocol<Transp>::run(bool) [with Transp = BlynkArduinoClientGen<Client>]'
D:/_ESPEASY_/ESPEasy-844915618f60f74405f93b3e0d79034d83a48e90/src/_C015.ino:70:15:   required from here
lib/Blynk/src/Blynk/BlynkProtocol.h:378:60: error: 'BlynkWidgetWriteInternalPinUTC' was not declared in this scope
         case BLYNK_INT_UTC:  BlynkWidgetWriteInternalPinUTC(req, param2);    break;
                                                            ^
lib/Blynk/src/Blynk/BlynkProtocol.h:382:61: error: 'BlynkWidgetWriteInternalPinMETA' was not declared in this scope
         case BLYNK_INT_META: BlynkWidgetWriteInternalPinMETA(req, param2);   break;
                                                             ^
lib/Blynk/src/Blynk/BlynkProtocol.h:383:60: error: 'BlynkWidgetWriteInternalPinVFS' was not declared in this scope
         case BLYNK_INT_VFS:  BlynkWidgetWriteInternalPinVFS(req, param2);    break;
                                                            ^
lib/Blynk/src/Blynk/BlynkProtocol.h:384:60: error: 'BlynkWidgetWriteInternalPinDBG' was not declared in this scope
         case BLYNK_INT_DBG:  BlynkWidgetWriteInternalPinDBG(req, param2);    break;
                                                            ^
*** [.pio\build\custom_ESP32_4M316k\src\ESPEasy.ino.cpp.o] Error 1

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Blynk in ESP32

#13 Post by Ath » 14 Sep 2021, 16:01

You could also download a compiled .bin (get the entire .zip file, then extract the build you need) from the Github PR
/Ton (PayPal.me)

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#14 Post by FanM » 14 Sep 2021, 16:33

The last one release with bin files is ESPEasy_ESP32_mega-20210802
I flashed ESP_Easy_mega_20210802_custom_ESP32_4M316k.bin
Yes, blynk is presents inside controllers, i will test it, thank you

I wonder, how it was compiled if library blynk was not working with ESP32 before...

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Blynk in ESP32

#15 Post by Ath » 14 Sep 2021, 17:25

That's not what I was trying to point at. From the PR that TD-er linked above you can get the sources local (google for the exact commands to get that local) so you can build your custom configuration, including the Blynk controller.
/Ton (PayPal.me)

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#16 Post by FanM » 14 Sep 2021, 22:14

Sorry, i am not a programmer. I am just a user. I can flash bin file, and now (thanks to you) i can compile source. Seems that is all what i can do :)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#17 Post by TD-er » 14 Sep 2021, 23:55

I had to modify the lib for Blynk as the library tries to do all sorts of things which are not the responsibility or task of a library like that.
For example it tries to make its own WiFi connection.

As I would say in Dutch: "Blijf met je tengels van WiFi af" :) (preferably with an accent from Amsterdam)

So you need to get the files in the lib directory too, as I put in that Pull Request.
If you need to have a test build, I can make one for you (or Ath can maybe do it, as I will be away all day tomorrow)

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Blynk in ESP32

#18 Post by Ath » 15 Sep 2021, 07:38

Well, I could make a build, but not before later today (evening, CET), as I have work-obligations all day (though WFH).
/Ton (PayPal.me)

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#19 Post by FanM » 15 Sep 2021, 09:43

Hi
No rush, i flashed ESP_Easy_mega_20210802_custom_ESP32_4M316k-factory.bin and it contain blynk.
I am not sure that this build contain all the devices and controllers i need, because i have only started to use it.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Blynk in ESP32

#20 Post by Ath » 15 Sep 2021, 10:01

That will be the Blynk HTTP controller, I assume, the Blynk 'native' controller isn't included.
/Ton (PayPal.me)

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#21 Post by FanM » 15 Sep 2021, 18:50

Actually i was thinking that i can use it the same way as original firmware (connect to blynk server and use blynk app). Seems i was wrong.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Blynk in ESP32

#22 Post by Ath » 15 Sep 2021, 20:04

I've pulled the PR local, modified the custom script for the 'regular' custom configuration to include the Blynk controller and Ser2Net plugin (and a few others I've been working on) and built the custom_ESP32_4M316k environment.
ESP_Easy_mega_20210915_custom_ESP32_4M316k.zip
(1.88 MiB) Downloaded 156 times
Contains both the normal .bin for updating via OTA, and factory.bin for updating via the flash tool.
/Ton (PayPal.me)

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#23 Post by FanM » 16 Sep 2021, 11:57

Thank you very much!!!

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#24 Post by TD-er » 16 Sep 2021, 12:23

Please let us know whether it is working.
See also the comments in this GitHub issue: https://github.com/letscontrolit/ESPEas ... -920773348

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#25 Post by FanM » 16 Sep 2021, 21:54

I stucked a little bit. The thing is that i need to operate my esp32, change relay status from any place in the World (like Blynk app).
But i cannot find some. Seems all controlles need a local server with software installed. And i can access to is only in local network or use static IP and make a port redirect to web server.
But what controller (service) i can use for state control from app or at least by using web service (not mine in my local network)?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#26 Post by TD-er » 16 Sep 2021, 22:36

I think this is exactly like the described request in the GitHub issue.
I have not used Blynk myself, so I can't tell you yet what is needed to fetch data from Blynk.

Usually receiving data is done via controllers that hold an active connection to a service like a MQTT broker.
There are online MQTT brokers to which you can connect and subscribe to some topics.
When publishing to such a topic, you can trigger actions, or change switch states.

So maybe you can have a look at the available online MQTT brokers? (N.B. we don't yet support SSL)
Or find a description of how Blynk sends back data to a client and then we can implement it.

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#27 Post by FanM » 16 Sep 2021, 23:26

I think i can write a php file on remote hosting, that can get data by controller http request. But what about send data back? It can answer, but how can espeasy receive that data and do something?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#28 Post by TD-er » 16 Sep 2021, 23:50

That's exactly why I mentioned the option for a MQTT broker as then the ESP maintains a connection.
When using HTTP this is way more complicated and will in practice turn out to be periodically polling.
So I don't think Blynk is the best way to do this... unless I'm wrong but then I need some example and documentation on how Blynk does support this.

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#29 Post by FanM » 17 Sep 2021, 09:10

Yes, i understand. But all MQTT brokers that mentioned in controllers in espeasy need to be installed on local computer. And access to that MQTT can be only from local computer. Access from another place possible only if i have static ip. But i need it to work on some remote server and have access to it from any place.
Yes, i found some free MQTT servers, but espeasy do not support them.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#30 Post by TD-er » 17 Sep 2021, 09:19

Which servers are there that do not work?
The OpenHAB/HomeAssistant MQTT controller is as basic MQTT as it can be.
The only important feature missing is SSL support.

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#31 Post by FanM » 17 Sep 2021, 09:26

Maybe i am wrong. Can i use it as remote broker (not local)?
I never worked with MQTT. But when i visited different MQTT websites, they offer to download a distribution and install it locally.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#32 Post by TD-er » 17 Sep 2021, 09:30

Yep, the MQTT client (the ESP) makes a connection to the broker, so the broker can also be online.
Make sure you increase the timeout in the controller settings as online services tend to take over 100 msec to reply due to "ping" distance.
So better set the timeout to something like 1000 msec.

FanM
Normal user
Posts: 35
Joined: 07 Sep 2021, 23:37

Re: Blynk in ESP32

#33 Post by FanM » 17 Sep 2021, 17:01

I am sorry, but i do not get it. The openhub offres a distribution to download:
https://www.openhab.org/download/
I should download and install it on my local pc.
But how to use remote openhub server?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Blynk in ESP32

#34 Post by TD-er » 18 Sep 2021, 14:50

Nope.
Just to explain what a controller does.

A controller receives values from a task and these will be sent in some form specific for a platform.
For example Domoticz HTTP does send it using just a regular HTTP GET only the URL is formatted in some specific format specific to Domoticz.
But it is just a HTTP url.
So you can even use them for your own project.

The same for Domoticz MQTT. It will publish the samples to a specified topic, where the message is formatted in specific formatted JSON.
The messages for Domoticz are published to domoticz/out and messages from domoticz to a node are published to domoticz/in.

So this is rather specific, as it is formatted in a specific JSON format and all nodes in the network see all messages.

For OpenHAB and HomeAssistant the topic structures can be structured exactly like you want like %sysname%/%tskname%/%valname%
And the values are just published as values, no specific formatting.
That's why I mentioned to use this controller as it is as basic as possible.

What you need is a MQTT broker. Most used broker is Mosquitto, which is available in most (Linux) distibutions.
But there are a lot of MQTT brokers, so you don't need to use Mosquitto. It can be just about any MQTT broker package.

For your own project, you can use a lot of libraries in a lot of languages to implement a MQTT client, so you can subscribe to the topics you push to to receive the data and publish to topics where your ESPEasy nodes subscribe to.

In short, the name "OpenHAB" in the controller name is just for which it is written, not limited to it.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Blynk in ESP32

#35 Post by Ath » 18 Sep 2021, 19:22

I'm not sure we're all on the same channel here :?

@FanM
TD-er was trying to point toward online MQTT services, where your ESP can publish it's results to, and you can get the data from using your phone or other device. In that case there is no need to install OpenHAB locally, but on ESPEasy the OpenHAB controller should be used as that is the most standard and straight forward MQTT implementations, plus it also supports the /cmd topic, that you can use to send commands to your ESP. The only snag there is that the online service must allow for http connections, as ESPEasy doesn't support https (because of the memory requirements of an SSL library).
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 40 guests