Wifi refinements for ESP8266 for gate opening #19252
Replies: 2 comments
-
|
Your code has a bunch of long sleeps that I suggest to break in loops of shorter sleeps to allow quicker response. I'm wondering if phones trying to connect to wifi is a good enough signal, if my phone has a good 5G signal, it won't consider trying to connect to a esp8266 slow AP, especially after it has learned in the past that that AP does not provide internet Perhaps using BLE Scanning is a better option. Simple on Android, more restricted on IPhone , but also possible using a simple BLE tag on the dash. |
Beta Was this translation helpful? Give feedback.
-
|
Your project of making a wireless switch using an access point (AP) on an ESP8266 or ESP32 is interesting. Here is my simple code that you might want to try. # wifi-switch (ESP8266)
import network, esp, time
# on esp32
# wlan.config(pm=network.WLAN.PM_PERFORMANCE)
# on esp8266
esp.sleep_type(esp.SLEEP_NONE) # alway stay awake, don't go to sleep
SSID = "Knight_Gate"
PWD = "LetMeInNow"
CNL = const(11)
AMODE = network.AUTH_WPA2_PSK
ap = network.WLAN(network.AP_IF)
def config(ap):
ap.active(True)
ap.config(txpower=20.5) # crash if bad power-supply
ap.config(hidden=False) # don't hide me
ap.config(essid=SSID, password=PWD, authmode=AMODE, channel=CNL)
def open_gate(w, ap):
# check friendly w here
print(f'>>>> gate open for {w}')
# gate open, disable your phone Wifi
# you may need to rescan WiFi
config(ap)
w, cln = b'', []
while True:
cln=ap.status('stations')
if not (cln and ap.isconnected()):
time.sleep(1);
w = b''
continue
else:
v = cln[0][0] # simple one at a time
# print('CLN:', cln) # debug
if v != w:
ap.active(False) # Disable WiFi
time.sleep(0.5) # sleep a while before switching the relay
open_gate(v, ap) # You need to disable your phone Wifi after gate opened
w = v
time.sleep(10) # sleep total period of gate open and close
config(ap) # reconfigure AP and ready for next roundRemember to add a 100 μF or larger electrolytic capacitor between the 3.3 V and ground pins to protect against power spikes. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello folks
I have a solar powered sliding gate with 2 remotes and a momentary switch on each side to manually trigger the gate to open. If the momentary switch is pushed while the gate is moving it will stop the gate. The gate opens for about 20 seconds, remains open for 30 seconds then takes another 20 seconds to close. After an initial push to start the opening process a subsequent push within 90(ish) seconds will cause the gate to stop and need to be manually reset.
I have intersected the momentary switch and wired in a relay triggered by an ESP8266 so that when a family member's mobile phone connects to the wifi access point the gate opens. I've drawn 12v from the dedicated connection point in the motor controller and used a buck converter to give the ESP8266 dev board a reliable 5v input. The relay gets 5v to the coil and 3.3v from pin5 to trigger the relay. It works but is far from optimal. My phone won't connect until I select the Knight_Gate network and even then sometimes it does not connect immediately. Also the Knight_Gate AP isn't always visible to my phone. Range isn't a concern - all this happens within 5m of the gate. It's far enough from my home wifi to not overlap. I'd like to drive up to my gate and have my phone reliably connect to the gate which will simulate a 1 second push on the momentary switch to open the gate.
I had intended that actual connection would not be necessary so I have created a list of recognised phone mac addresses. I don't think it causes a problem but can remove that feature it if it causing a problem.
Some of the trouble is surely with my phone but if there are improvements to my code that will make the wifi more reliable so that every time my phone looks for the gate it finds it and can successfully connect I will be very grateful for guidance.
Beta Was this translation helpful? Give feedback.
All reactions