The gateway is configured to accept data from many sensors and distribute the data to many applications.
- Initial Setup
- Find the IP Address of the BBB
- Getting Data from BLE Devices On Your Computer
- Hacking the Gateway
To setup the gateway plug the BBB into a ethernet network and then power it with the included power adapter. The BBB will use DHCP to obtain an IP address.
The first step is to find the IP address of the BBB. To help with this, the BBB is identifying itself on:
- mDNS
- SSDP/UPnP
- BLE/Eddystone
To find it, you have a few options:
-
Summon App: Download the Summon app for Android or iOS. This app will find the BLE packets from the nearby SwarmGateway. Alternatively, you can use the Nordic BLE App and look for a device with the name "swarmgateway". Both apps will display the IP address.
-
Try using the mDNS URL: If mDNS lookup is working, and you are on the same network as the BBB, you should be able to view swarmgateway.local.
-
Use the find-my-gateway.js script: We have a node.js script that searches for the BBB on all of the protocols.
-
Use the discovery protocols directly: If you have a tool you like for any of the discovery protocols, you can use that directly.
-
mDNS: Look for services matching
_workstation._tcp
with the nameswarmgateway
. On Linux:avahi-browse _workstation._tcp
-
SSDP/UPnP: Look for the
urn:TerraSwarm:gateway:1
profile. -
BLE/Eddystone: Scan for BLE advertisements with device name
swarmgateway
. The IP address is encoded in them as ASCII.
-
-
Use nmap: Scan for all devices with port 3001 (the websockets port) open:
nmap -sV -p80 --open <any ip address on the gateway network>/24
You could also use ports 1883 (MQTT), 80, or 22.
Data from BLE devices is collected by the BleGateway core application which runs on the SwarmGateway by default. Devices which support this gateway point the gateway to a device-specific "parser" JavaScript function that converts their BLE advertisements to key,value JavaScript objects. Those objects are then passed to subscribed applications.
You can access these packets over a couple protocols once you know the IP address of the BBB gateway (or if you are on the same LAN). For code examples, look here.
-
Quick View
To view a very simple UI with the recent data, go to:
http://<ip address of the gateway>
This will display all of the devices the gateway has seen and their last ten packets.
-
WebSockets
To retreive as a websocket stream, connect a websocket client to
ws://<ip address of the gateway>:3001
All packets the gateway sees will be sent to each client connected via websockets.
-
Ptolemy
To get packets from the gateway to Ptolemy, add a
WebSocketClient
accessor with the IP address of the BBB as theserver
field and 3001 as theport
field. See an example in theptolemy
folder.
-
-
MQTT
To retreive data from a MQTT topic, install MQTT and run:
mosquitto_sub -h <ip address of the gateway> -t gateway-data
-
UDP Broadcast
Packets are sent as JSON encoded strings in UDP packets to the broadcast address
255.255.255.255
on port3002
. -
Retrieving from GDP
If you have the GDP client installed (or you can run this on the SwarmGateway) you can query packets from GDP by reading the correct log. The log name is
org.terraswarm.gatewayv1.<MAC address of gateway>
. For example:org.terraswarm.gatewayv1.84eb1898b4a8
.gdp-reader -s org.terraswarm.gatewayv1.<BBB MAC address>
The above protocols and the examples in the examples
folder can also
run directly on the gateway. To connect:
ssh debian@<ip address of gateway>
See the TerraSwarm wiki for the password.
In the $HOME
folder is this repository. Running git pull
in that folder
will update the code to the latest version.
cd urban-heartbeat-kit
git pull
Four main services are configured to start at boot:
gateway-publish
: Recieves BLE packets and publishes them on the various protocols.gateway-server
: Displays the received packets in a web interface.gateway-mqtt-topics
: Sends data from each device to its own MQTT topic.ble-address-sniffer-mqtt
: Publish all seen BLE addresses on the MQTT topicble-advertisements
.gateway-gdp-publish
: Publish gateway packets to a GDP log.adv-gateway-ip
: Broadcast the gateway IP address over BLE/Eddystone.
Each service is running inside of systemd. To stop a service:
sudo systemctl stop <service name>
To restart a service:
sudo systemctl restart <service name>
To stop a service from running at boot:
sudo systemctl disable <service name>
There are several data streams coming from the SwarmGateway.
Topics:
gateway-data
: ALL formatted data packets from nearby devices.ble-advertisements
: ALL BLE MAC addresses seen at this gateway.gateway-topics
: List of device-specific topics available at this gateway.device/<device type>/<device id>
: Data stream from specific devices.
If you would like to publish data to a EmonCMS installation, do the following steps on the gateway:
-
Edit
/etc/swarm-gateway/emoncms.conf
with the credentials to your install. -
Enable the publishing service:
sudo systemctl enable gateway-mqtt-emoncms sudo systemctl start gateway-mqtt-emoncms
All devices the BleGateway finds will be published to emoncms.
The gateway can store all packets to local storage. To configure this:
-
Edit
/etc/swarm-gateway/log.conf
and make sure there is a keylog_file
like so:log_file = /media/sdcard/gateway.log
-
Then enable the logging service:
sudo systemctl enable gateway-mqtt-log sudo systemctl start gateway-mqtt-log
In this example, all packets will be stored in files like
/media/sdcard/gateway.log.8.gz
.
If you would like to publish data to GATD via HTTP do the following:
-
Edit
/etc/swarm-gateway/gatd.conf
with the HTTP POST urlpost_url = http://post.gatd.io/...
-
Then enable the GATD posting service
sudo systemctl enable gateway-mqtt-gatd sudo systemctl start gateway-mqtt-gatd
All devices the Gateway finds will be published to GATD.
Adafruit has instructions for setting up a WiFi connection located here. Do not perform the kernel upgrade step (first step) since that has already been run on the Beaglebone gateway.
The GAP cape for the BBB provides two 802.15.4 radios fully supported by the Linux kernel.
For instructions, see the GAP Readme.
View that the microphone is attached:
arecord -l
Record an audio sample:
arecord -D hw:1 -r 44100 -f S16_LE sound.wav