Author Topic: PLUGIN: Unifi Sensor - Presence detection using a Unifi Wi-Fi controller  (Read 3045 times)

Offline Buxton

  • Full Member
  • ***
  • Posts: 129
  • Karma: +9/-0
Hello Spanners,

I was hoping to install the unifi plugin on openLuup. I started reading through the code to see if I could catch any problems upfront and so far nothing stands out. But I did want to ask why you used a script with curl for the unifi data retrieval--as opposed to Luup's inet.wget.  I thought about moving the script calls/logic from the script into the body of the plugin but it wasn't clear if there was a specific reason for you creating the program this way, so I thought I'd ask ahead of time.... 

I was using the plugin without fail for a while--it's an awesome bit of software, but because of performance issues related to the veralite hardware, I am now moving almost all plugins from my veralite to openLuup.  Therein the reason for my question.....  Any help appreciated.

Offline Spanners

  • Sr. Member
  • ****
  • Posts: 258
  • Karma: +16/-5
Hi Buxton,

The reason for using curl in the script was simply that I couldn't find a good example of using https/POST and authentication with wget at the time. After a bit of fiddling around and getting nowhere I went with "it works, good enough" then moved on to other projects.

I was hoping someone who had more Lua experience would post and example and I could recut the Plugin to be Lua only.

I don't see any reason why it couldn't be made to work unless there's a limitation of of wget I'm not aware of. That's a question for the more learned forum members.



Offline akbooer

  • Master Member
  • *******
  • Posts: 6153
  • Karma: +275/-69
  • "Less is more"
As the name suggests, luup.inet.wget() only does GET and not POST requests.  That being the case, you'd have to use the long form of http.request() to do a POST.  It's not difficult and should be compatible with both Vera and openLuup.

I generally deplore the use of os.execute() if it can at all be avoided, but needs must, and if it ain't broke, then there perhaps isn't a need to fix it.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline Buxton

  • Full Member
  • ***
  • Posts: 129
  • Karma: +9/-0
Yeah, I didn't catch the Post parameter in the one curl call.  Here's an example of using Post in http.request in a plugin by a-lurker https://github.com/a-lurker/Vera-Plugin-Irrigation-Caddy.  His function handles return values as well as parameterized calls. Note the require of the socket library.

I keep waiting for Ubiquity to put some sort of device status in their Unifi controller that can be pushed or directly accessed, or even in their router UI (I use the ERL in addition to their WAPs). It seems like a no brainer for instant occupancy status, and I often see requests for the feature, but as far as I know, there's currently only polling through the API.

Good to see you back AK! :)