From ad9065ebee912a1a1ac4c081e997ec76195e402a Mon Sep 17 00:00:00 2001 From: blakadder Date: Sat, 13 Nov 2021 22:57:25 +0100 Subject: [PATCH] Update Berry-Cookbook.md --- docs/Berry-Cookbook.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/Berry-Cookbook.md b/docs/Berry-Cookbook.md index a37f6ae0c3..145474445a 100644 --- a/docs/Berry-Cookbook.md +++ b/docs/Berry-Cookbook.md @@ -637,4 +637,24 @@ This project is a multi-zone heating controller written entirely in berry. It de [https://github.com/Beormund/Tasmota32-Multi-Zone-Heating-Controller](https://github.com/Beormund/Tasmota32-Multi-Zone-Heating-Controller) +## Ethernet Network Flipper +Used on board with Ethernet. If both Wi-Fi and Ethernet are active, turn off Wi-Fi. Place code in `autoexec.be` to execute on boot. You can call the function from Berry console any time with `netflip()`. + +``` +def netflip() + var eth = tasmota.eth().find('ip') != nil #1 + if tasmota.wifi().find('ip') != nil == eth #2 + tasmota.cmd('Wifi ' .. (eth ? 0 : 1)) #3 + end +end +tasmota.set_timer(30000,netflip) #4 +``` +1. store variable "eth" with Ethernet status - "true" if Ethernet IP exists and "false" if not +2. check if wifi status is true and compare to eth status +3. send command `Wifi` with parameter depending on eth variable. `..` is to concatenate a string. See Berry [manualg(https://github.com/berry-lang/berry/wiki/Chapter-3#-operator-1) +4. set a timer to execute the netflip function 30000ms (30 seconds) after loading `autoexec.be` + + + +