logo elektroda
logo elektroda
X
logo elektroda

How to Scan Local Network for OBK Devices After WiFi Pairing and Find Assigned IPs?

p.kaczmarek2 21 6
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21691640
    p.kaczmarek2
    Moderator Smart Home
    @divadiow @insmod @max4elektroda
    I've got some random idea on how to improve pairing with WiFi. Currently, when you pair device with your router, you don't get to see a new IP that was received it. And we don't have a mechanism to have both AP and STA at the same time....
    But what if we add a little script to pairing page? Remember the device MAC in Javascript and then, in JS loop, iterate local IP addresses (?), query obk endpoint and see if there is a matching one?
    There is however one issue - can we somehow figure out the range of IP addresses to check while being in that browser page? I usually pair my devices on my laptop, which is also connected to network via cable... what about phones? If you exit device AP and connect back to your WiFi, would that still work?

    I didn't do any testing yet, it's just a random idea
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #2 21691668
    divadiow
    Level 36  
    yes, that'd be useful. kinda like how Tasmota web installer gives you the link to real device after you've configured and joined wifi? Won't that mean having OBK join wifi without reboot? or joining, scan/reporting IP to browser then rebooting?
  • ADVERTISEMENT
  • #3 21691673
    p.kaczmarek2
    Moderator Smart Home
    I think ESP has dual AP + STA mode support. We dont' have this officially in OBK.

    I am rather thinking about a little Javascript that queries first common gateway/ip addresses and then scans network. How often do people have 192.168.0.1 LAN with 255.255.255.0 mask? There are 255 IPs to check (or less, we can skip gateway, etc), I don't think that checking 255 IPs would take long in a modern browser. You can also play with it in separate html file, ask ChatGPT to create a scanner that queries network for tasmota devices, OBK supports cm ? cmnd STATUS endpoint like Tasmota. Hmmm.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #4 21691696
    divadiow
    Level 36  
    I imagine it’s safe to assume that most people will add their converted devices to a basic home network, where the device will receive an IP address in the same subnet as the management device.

    Of course, there will be exceptions — for example, if someone uses an IoT VLAN or another network setup that prevents the newly leased IP from being accessible from their management device.
  • #5 21691936
    insmod
    Level 28  
    I have router at 192.168.1.1 with 255.255.254.0 mask (and 255.255.255.0 for dhcp, so that devicers with static ip use 192.168.0.x addresses and dhcp devices use 192.168.1.x).
    No idea about the script, i've never had the problem with getting the ip of a newly flashed device. In openwrt, i just look at "Active DHCP Leases" table.
    And wouldn't it be easier to get the ip by hostname rather than by mac? Although then the problem is setting up the correct local domain (like esphome default is .local, while i use .lan).
  • #6 21692114
    max4elektroda
    Level 21  
    I like the idea of getting the new IP "served" instead of looking for it but I wonder how to do it. The only idea to get a probably correct one without scanning would be on a quick thought to

    get WiFi credentials from AP mode,
    connect (which means reboot) and somehow save the IP
    restart in AP mode to "report" the IP (using the fact that usually it will get the same IP on next boot in STA mode) .

    If we could do all steps without rebooting, it would be much easier.

    So there might be a simpler way, but trying the name might be easier, if your router registers the name.
  • ADVERTISEMENT
  • #7 21693934
    max4elektroda
    Level 21  
    Added a simple scanner for OBK devices to WebApp https://github.com/OpenBekenIOT/webapp/pull/225

    You can define the network and hosts to scan (and a timeout).
    It will try to open
    http://${ip}/cm?cmnd=STATUS%205
    which will work for OBK devices thanks to
    "Access-Control-Allow-Origin *" in OBK.





    General idea:
    If you add a new device, you load "WebApp" (possible even in AP mode) and then add WiFi credentials in GUI.
    After restarting device in STA mode, you can "scan" the network in the WebApp to find out the IP of the new device (and possilbe other OBK devices) in WebApp even if device was restarted and is no longer available in AP mode.
ADVERTISEMENT