Announcement

Collapse
No announcement yet.

Presence detection with openwrt via MQTT

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Presence detection with openwrt via MQTT

    Here is the link to this project .
    https://github.com/dersimn/owrtwifi2...ster/README.md

    I could install openwrt on my linksys 3200acm .

    But I would prefer to turn it into an AP, an do the routing tasks with another device running openwrt...so I could place the ap where I want near one of my switches. Anyone have an idea?

    I have two options, I think.

    -Buy a little pc (would prefer arm I think for power consomption)that have a wan a lan port and try to convert it to a mini openwrt router. The pi seems powerfull enough for this( or maybe not) ..but I need to have a +450 mbs connection.

    -Buy another wifi router, and use it only for routing.

  • #2
    Is your objective to detect presence of mobile devices and have it reported via MQTT? If so, why not just install a MQTT client on each mobile device and look for the LWT to know when offline vs. online?

    Comment


    • #3
      Thanks Micheal. I didnt think about mqtt client on phones. Will chek on ios side.



      I’ll maybe just finish with a ubiquity edge router . For my second objective

      Comment


      • #4
        Wanted to try the package here. So installed openwrt on my linksys router. I think the linksys has a lot of cpu overhead compared to other router.. for what i have seen.
        So I don't think it will becomes an issue. And yes i am intrigued by the Unify tendency... but it is way overpriced.

        __

        So , this is the first time a tracking method is able to track the two Iphone here without false ''outside'' detection ( Iphone tends to go in sleep mode )

        The only one (false detection) is obviously when i go to bed and set my phone in ''plane'' mode. But this can by in fact be useful.
        **My iphone 7 does not have any false offline detection. But the iphone 6s of my girlfriend does ( not frequent) (See graph: I have to ask my girlfriend if she went outside or maybe we have a dead wifi spot somewhere)


        What i like about this approach:

        1. No polling at all (push from mqtt)

        2. Instant status

        3. A) Woks really nice for detecting iphone presence.
        B) at the limit you can set an event like this: if Iphone is set to ''del''(entry deleted from router wifi's) by router | and if battery is not is not low | and if geofency said you are home ---- then set this virtual device ''iphone Matt'' to ''Is sleeping''.
        C) or another event phone is awake : if Iphone is set to ''new'' (new entry in router wifi) by router | and if geophency said you are home ---- then set this virtual device ''iphone Matt'' to ''Is ''awake''

        4. With multiple openwrt ''ap'' in the house. You can in fact track someone in the house with this method. ( A low cost watch that connect to the wifi would maybe do the tricks;: I do not see myself bringing my phone everywhere in the house lol)

        5. Iphone ( or any other wifi device) battery is not drained by polling.

        6. with mcsmqtt it is very easy to detect new people connection on the wifi ( see picture). Each new entry are added to mcsmqtt database!

        7. Do not ''waste'' cpu cycles by polling the device every seconds ( I am doing this with Norered with 2-3 other devices).

        8. Any new entry is listed with the mac address ! So if the router assign a new ip to a guest... who cares.


        What I do not like :

        1. The ''iw event'' detection ( see end of page of the link i posted , or see code) only works with wifi devices.



        ------


        For testing this, you can in ssh, send a ''iw event'' command to the CLI and you will understand how the iw package works.










        Attached Files

        Comment


        • #5
          What I understand is that you need to use an AP that runs under openwrt and the script will be looking at the status tables maintained by the AP. it will report changes in connection status. I do use ubiquiti for my AP. I think I have seen mqtt client for it, but have not looked into it.

          You mentioned tracking which I assume is based on RSSI with an approach similar to what I did for Bluetooth and mcsMQTT. in the past I had 4 AP to get desired coverage while now I just use a single AP. It seems to me that a client/phone connected to a single AP at a time which would seem to me to make it hard to do location isolation.

          Comment


          • #6
            Yes the Bluetooth approach seems more preferable/reliable versus multi ap! for indoor tracking. I am following your thread , Not sure when I'll be able to learn/configure that part.

            There is a node package here https://github.com/hobbyquaker/unifi2mqtt .But I guess it is polling, since it is an node package.

            Last edited by MattL0; May 30th, 2019, 03:32 PM. Reason: Removed mqtt-arp package. Can't compile this package.

            Comment


            • #7
              Install the packages
              • mosquitto-client
              • coreutils-nohup

              with either luci or opkg. Create user (optional)

              It's recommended that you create a new user on your OpenWRT Router for this. Better don't use root for this script (just in case).

              Unfortunatedly there isn't something like adduser available, so edit the configuration files manually. I recommend doing this via SCP or using nano on the command line:

              In /etc/passwd:
              presencedetector:*:1001:1001resencedetector:/:/bin/false
              In /etc/group:
              presencedetector:x:1001:
              In /etc/shadow:
              presencedetector:x:0:0:99999:7::: Copy over the scripts

              Again, use SCP for that or Copy&Paste the contents via command line. I'd recommend to place them under
              • /usr/bin/presence_detection.sh
              • /usr/bin/presence_event.sh
              Create Cron job

              Create initial contab:
              crontab -e -u presencedetector
              Add a line for the script:
              */1 * * * * /usr/bin/presence_detection.sh
              Enable Cron:
              /etc/init.d/cron start /etc/init.d/cron enable Add event-based script to rc.local

              Place the following line
              nohup /usr/bin/presence_event.sh >/dev/null 2>&1 &
              inside the /etc/rc.local file before the exit 0. You can to this via command-line or via LuCI in System -> Startup -> Local Startup. The script will be executed after reboot.

              Comment

              Working...
              X