Skip to content

Example to forward BLE beaconing sensors into MagicMirror² platform

License

Notifications You must be signed in to change notification settings

mattileh/MMM-SensorGateway

Repository files navigation

MMM-SensorGateway

Want to get Live Sensor data to your mirror without touching the Pi hardware? This module enables taking a shortcut by utilizing the BLE advertisment beacons from sensors and route that info via gateway into MagicMirror² platform.

MagicMirror² platform

MagicMirror² 3rd party modules

Movesense

Ruuvi

Example UI of module installed

Example UI

  • RuuviTag(s) environment information is routed to MagicMirror platform.
  • (optional) Movesense tag is used as a control platform / "poor man's" power switch for demo purposes

Installation guide

Out of scope

  • configuring BLE interface on RasPi in hci0
    • hcitool dev should print out something similar Devices: hci0 B8:27:EB:A9:02:03
  • Install python library for RuuviTag (see : https://github.com/ttu/ruuvitag-sensor/blob/master/install_guide_pi.md ) and verify tags can be seen (use for example ruuvitag -f section of instructions)
    • Python 2.7 tested on this project scope.
    • NOTE Currently only data format 3 protocol specification (RAWv1) supported,which was the current during the module dev time. SHOULD be updated to protocol 5 as 3 is obsolete (see more from Ruuvi's github) - PRs welcomed!
  • Updating Movesense firmware (Movesense has a sample app that can do the FOTA update)
  • Finding out the MAC addresses of the beacons (you can use, for example, NRFConnect(https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=fi) or the mobile applications provided by Movesense and Ruuvi

Clone and configure module

  • Clone MMM-SensorGateway under modules in the MM2 platform as all 3rd party modules
  • run npm install in module's directory to install websocket and exec modules.
  • Configuration (into config/config.js) :
{
	module: "MMM-SensorGateway",
		position : "bottom_bar",
		config : {
			controlsensor:
			{
			type: "movesense",
				MAC : "01:11:12:C2:18:04"
			},
			envsensors : [
			{
			type: "ruuvi",
				location : "Living room2",
				MAC : "FE:11:11:1C:11:11"
			},
			{
				type: "ruuvi",
				location : "Bedroom",
				MAC : "D3:21:CC:34:DF:95"
			},
			{
				type: "ruuvi",
				location : "Balcony",
				MAC : "CE:90:63:D7:33:60"
			}
		]
	}
},

controlsensor is optional configuration block

MAC please note all MAC ADDRESSES are in UPPERCASE

location is arbitrary string

type is for future development

Install script for Gateway

  • run install script with root priviledges : MMM-SensorGateway $ sudo ./install.sh
    • This will install required bluetooth, Ruuvi and websocket related packages (see the script for details)
    • This will also setup an service that will kick in during RasPi boot-up
  • Expected final output
Remove existing service
Removed /etc/systemd/system/default.target.wants/local_blegateway.service.
Creating service
Write service file
Write launcher file /usr/share/local_blegateway/local_blegatewaykickstart.sh
Enable service
Created symlink /etc/systemd/system/default.target.wants/local_blegateway.service → /lib/systemd/system/local_blegateway.service.

If everything went well, service can be started, stoped and status checked
by normal service commands, like:
   sudo service local_blegateway start
   sudo service local_blegateway status
   sudo service local_blegateway stop
  • Start service (or reboot Pi) : sudo service local_blegateway start
    • (optional) verify that service is running:
sudo service local_blegateway status

--> you should expect seeing the packets routed:

Oct 16 19:45:40 raspberrypi local_blegatewaykickstart.sh[962]: {'temp': 22, 'battery': 0, 'state': 1, 'packet': 189, 'MAC': '0A:1C:1C:12:18:04', 'type': 'movesense'}
Oct 16 19:45:40 raspberrypi local_blegatewaykickstart.sh[962]: {'acceleration': 1003.0807544759296, 'pressure': 1008.86, 'temperature': 20.17, 'acceleration_y': -9, 'acceleration_x': -9, 'battery': 3043, 'acceleration_z': 1003, 'data_for

Troubleshooting

  • Gateway and MM2 module uses TCP port 8001 for communicating (check if another software is using this)
  • Gateway can be changed to route beacons to local network (for example debugging from PC). See def _main(argv): in bleAdvWebSocket.py
  • Run gateway manually go to gateway folder and sudo python bleAdvWebSocket.py
  • Check that MAC ADDRESSES are in UPPERCASE in configuration
  • RuuviTags are broadcasting with Data Format 3 Protocol Specification (RAWv1)

Special thanks

About

Example to forward BLE beaconing sensors into MagicMirror² platform

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published