automation - ansible - sync of rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

automation - ansible - sync of rules

#1 Post by tkocher » 24 Aug 2022, 10:06

Hello,

I have about 10 nodemcus / wemos with easyesp in my house.
for connectivity problems and also for reporting I have created some rules and also to keep wifi backup ssid config etc in sync I would like to have some orchestration of all of them to keep at least 1 rule set in sync and also all other basic settings.

From technical perspective ansible would do the job, however I am not very familiar with ansible, so can someone provide how to access the nodemcus. Even more as I do not find the config parameters as API call....

Thanks for examples...

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

Re: automation - ansible - sync of rules

#2 Post by Ath » 24 Aug 2022, 11:31

Some commands, especially for configuration, are not accessible directly from a url (like /cmd=taskenable%2C6 etc.), but you can run a rule, with arguments, from that url, /cmd=event%2CupdateGeneralConfig%3Dtest1%2Ctest2%2Ctest3 (command: event,updateGeneralConfig=test1,test2,test3)
Then, in your rules you can handle that input:

Code: Select all

on updateGeneralConfig* do // Add * to handle 1st argument as string
  WiFiSSID2,%eventvalue1% // Secondary SSID name
  WiFiKey2,%eventvalue2% // Secondary SSID password
  // etc.
  Save // Persist settings
endon
/Ton (PayPal.me)

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#3 Post by tkocher » 24 Aug 2022, 12:23

thanks Ath!

so my idea is to have one scratch rule file, eg rules4.txt and then question is how to update or upload this specific rule file to all easyesp hosts and then I can execute the file on all systems...
2 step approach...

any hint how to get the file from remote to each easyesp host?

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

Re: automation - ansible - sync of rules

#4 Post by TD-er » 24 Aug 2022, 12:52

There is an experimental feature called FEATURE_CUSTOM_PROVISIONING, which is not yet included in official builds.
Only in custom builds.
This allows to download files from a HTTP server using a command.
So then you could define the URL in the rules and the settings archive page and issue an event to trigger the download of the file.

The command (to call from within the rules) is then "provisionrules" to fetch a rules file.

But like I said, it is not yet available in official builds.

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#5 Post by tkocher » 25 Aug 2022, 22:11

cool function!
However I always get a timeout of the rules4.txt file.

If I use the URL http://172.30.1.10/rules4.txt in the browser I see the file content...

In the syslog of the nodemcu I see after executing following command: curl http://172.30.1.57/control?cmd=ProvisionRules,4

Aug 25 22:06:00 ESP-Easy EspEasy: EVENT: Clock#Time=Thu,20:06
Aug 25 22:06:00 ESP-Easy EspEasy: EVENT: Clock#Time=Thu,20:06 Processing time:3 milliSeconds
Aug 25 22:06:02 ESP-Easy EspEasy: HTTP: ProvisionRules,4
Aug 25 22:06:02 ESP-Easy EspEasy: HTTP after parseTemplate: ProvisionRules,4
Aug 25 22:06:02 ESP-Easy EspEasy: Command: ProvisionRules
Aug 25 22:06:02 ESP-Easy EspEasy: ProvisionRules,4
Aug 25 22:06:02 ESP-Easy EspEasy: Par1: 4 Par2: 0 Par3: 0 Par4: 0 Par5: 0
Aug 25 22:06:02 ESP-Easy EspEasy: CRC : ProvisioningSettings CRC ...OK
Aug 25 22:06:02 ESP-Easy EspEasy: downloadFile: URL: http://172.30.1.10/rules4.txt decoded: 172.30.1.10:80/rules4.txt
Aug 25 22:06:02 ESP-Easy EspEasy: HTTP : DownloadFile 172.30.1.10 GET... HTTP code: 200
Aug 25 22:06:04 ESP-Easy EspEasy: Timeout: rules4.txt
Aug 25 22:06:04 ESP-Easy EspEasy: sendcontent free: 16752 chunk size:19
Aug 25 22:06:04 ESP-Easy EspEasy: sendcontent free: 13552 chunk size:0
Aug 25 22:06:04 ESP-Easy EspEasy: EVENT: http#172.30.1.10=200
Aug 25 22:06:05 ESP-Easy EspEasy: EVENT: http#172.30.1.10=200 Processing time:82 milliSeconds

As easyesp SW I use: ESP_Easy_mega_20220809_custom_beta_ESP8266_4M1M

As URL I have configured: http://172.30.1.10 (and have checked "Fetch rules4.txt:").

apache logs looks good as well (no authentication required)
172.30.1.57 - - [25/Aug/2022:22:10:15 +0200] "GET /rules4.txt HTTP/1.1" 200 306 "-" "ESP Easy/20116/Aug 9 2022 09:52:15"

any idea?

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

Re: automation - ansible - sync of rules

#6 Post by TD-er » 25 Aug 2022, 23:12

What version of the code do you use?
It looks like it is still using the old code, which I merged a fix for today.
See: https://github.com/letscontrolit/ESPEasy/pull/4205

I did not check the download call myself in this latest code, but given you are seeing the timeout, I guess it is still the "old" code I was working on yesterday.

You can download a GitHub Actions test build including these fixes here: https://github.com/letscontrolit/ESPEas ... 2925712474
N.B. You need to be logged in into GitHub to download the "Binaries" right under the header "Artifacts"

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#7 Post by tkocher » 26 Aug 2022, 07:37

great support thanks, so I installed following version:
ESP_Easy_mega_20220825_custom_beta_ESP8266_4M1M
However same timeout behavior :-(

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

Re: automation - ansible - sync of rules

#8 Post by TD-er » 26 Aug 2022, 14:43

Thanks for the feedback.
I will try it myself and see whether I missed a specific use case there.
Will get back to you.

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#9 Post by tkocher » 30 Aug 2022, 21:38

and I miss the notification menu, are you aware of this topic, nevertheless notifications are working.... :-)

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

Re: automation - ansible - sync of rules

#10 Post by TD-er » 30 Aug 2022, 22:41

Yep I am aware and it is on my todo-shortlist.
But as you may have seen by the nr of commits the last few days, I've also been busy on other parts of the code.

Since there was quite a serious issue on some ESP32 boards, I plan on making a new build soon and I will also try to fix your download issue and have it included in that build too.

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#11 Post by tkocher » 30 Aug 2022, 22:45

no hurry...

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#12 Post by tkocher » 11 Oct 2022, 07:56

days are getting shorter, so asking for any update? :-)

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

Re: automation - ansible - sync of rules

#13 Post by TD-er » 11 Oct 2022, 08:47

Have not yet tested the download feature myself, but I have been making quite some code changes in that department.
Perhaps you could test this (pending) PR: https://github.com/letscontrolit/ESPEas ... 3218259124

N.B. it also includes some first implementation of mine to add NTP-like support via p2p nodes, so you might see "strange" system times when the node cannot reach a NTP server itself but is having the same UDP port configured on multiple nodes in the network (still working on that fix)

Edit:
Just browsing through the previous posts...
How quickly may the host reply which is serving the files? Maybe it is just a simple fix to increase the timeout?

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#14 Post by tkocher » 16 Oct 2022, 11:45

as I have problems with OTA of the nodemcu with the beta from August I ask for further time.
Seems I need to flash the nodemcu (or use another one) however unfortunately I installed it on an nodemcu which is not that accessible :-(
Unfortunately I had not tested the OTA on the August beta version.
It seems to upload the file, then reboot - however it comes back with the old image :-(

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

Re: automation - ansible - sync of rules

#15 Post by TD-er » 16 Oct 2022, 12:49

A few tricks to help it succeed OTA on unstable WiFi connections:

- Let a ping run from whatever computer to that ESP node during flash
- disable a few tasks, especially ones using SW serial and/or GPIO-0
- Flash the .bin.gz file as it may take less time to transfer
- Set WiFi TX power to max.
- Disable ECO mode
- try flashing from a computer connected to the same WiFi access point, or if that doesn't work, try flashing from a computer actually not connected to WiFi.

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#16 Post by tkocher » 08 Jan 2023, 20:30

tested after long time again image: ESP_Easy_mega_20221224_custom_beta_ESP8266_4M1M.bin
However still had problems to load a rules file.
Apache config provided access log, and it is downloadable from normal browser, however in nodemcu the file size is always "0"...
The link you provided long time ago for a special build to test is not completely downloadable for me...

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

Re: automation - ansible - sync of rules

#17 Post by Ath » 08 Jan 2023, 22:44

tkocher wrote: 08 Jan 2023, 20:30 Apache config provided access log, and it is downloadable from normal browser,
Where did you get any Apache access log?
tkocher wrote: 08 Jan 2023, 20:30 however in nodemcu the file size is always "0"...
What operating system and browser (versions) are you using? Any security software installed, like antivirus? Brand and versions too, please.
tkocher wrote: 08 Jan 2023, 20:30 The link you provided long time ago for a special build to test is not completely downloadable for me...
Those download links tend to expire, but if the file is actually there, but you're unable to download, I suspect you have something running on your computer that is interfering with the up- and download of files...
/Ton (PayPal.me)

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#18 Post by tkocher » 09 Jan 2023, 09:14

Hello,

I am talking about the provisioning feature, so esayesp can download a new rules file via http.
Where did you get any Apache access log?
on the linux server, the provisioning URL is pointing to.
What operating system and browser (versions) are you using? Any security software installed, like antivirus? Brand and versions too, please.
As mentioned I used the SW version on the nodemcu ESP_Easy_mega_20221224_custom_beta_ESP8266_4M1M.bin and I try to download a rules file from debian apache. Based on following trigger:

Code: Select all

on fetch_rules4 do
  ProvisionRules,4
  endon
Those download links tend to expire, but if the file is actually there, but you're unable to download, I suspect you have something running on your computer that is interfering with the up- and download of files...
agree, however I do not know if it makes sense to invest time is such an old status either...

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#19 Post by tkocher » 08 May 2023, 18:38

GREAT!

I tried to download a rules file and it worked, I am exited.
Now I need to play a little bit how to adjust setting with a rules file.

When it is expected that that the custom feature is included to the normal version?
As I am missing notifications with customs version :-) And the colored rules syntax is nice as well...

Thanks!

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

Re: automation - ansible - sync of rules

#20 Post by TD-er » 08 May 2023, 22:01

Not sure if the provisioning feature will ever be included in a non-custom build.
Problem is that it may allow for an unexpected 'back-door' kind of feature if someone doesn't really know what is enabled and what isn't.

On the other hand, the way we now make builds is no longer practical as you simply can't make good selections of plugins suitable for everyone.
So we really really need to make a build service/server so everyone can make their own custom builds.

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#21 Post by tkocher » 08 May 2023, 22:11

Valid approach, it there another approach to do automation? Kind of API?

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

Re: automation - ansible - sync of rules

#22 Post by TD-er » 08 May 2023, 22:17

Well at least the provisioning stuff is now documented :)

https://espeasy.readthedocs.io/en/lates ... ovisioning

And there are also optional deployment and support wifi credentials:
https://espeasy.readthedocs.io/en/lates ... redentials

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#23 Post by tkocher » 08 May 2023, 22:57

Is normal configuration not unencrypted as well?

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

Re: automation - ansible - sync of rules

#24 Post by TD-er » 08 May 2023, 23:01

What do you mean by "not unencrypted" ?

tkocher
Normal user
Posts: 15
Joined: 08 Jul 2020, 12:34
Location: Germany

Re: automation - ansible - sync of rules

#25 Post by tkocher » 09 May 2023, 07:00

I access the UI per http and not per https either

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

Re: automation - ansible - sync of rules

#26 Post by TD-er » 09 May 2023, 09:40

I have a pending PR (not yet ready) to support TLS for MQTT. (ESP32 only)
Not yet for accessing the web UI via HTTPS.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 28 guests