Skip to content

Commit

Permalink
include the status of the nexusedge service in the gateway heartbeat.…
Browse files Browse the repository at this point in the history
… increase freq of heartbeat to every min.
  • Loading branch information
nabeel-nasir committed Feb 22, 2022
1 parent cae9751 commit 046c2c9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
22 changes: 0 additions & 22 deletions platform/utils/send-heartbeat.js

This file was deleted.

33 changes: 33 additions & 0 deletions scripts/send-ne-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# this script sends the status of the "nexusedge" service running on the gateway to an mqtt topic every minute

filename="/etc/gateway-id"
if [ -s "$filename" ]
then
id=$(cat /etc/gateway-id)
else
id=$(cat /sys/class/net/wlan0/address | sed 's/://g')
fi

while sleep 60
do
# get the status of the nexusedge service. the command returns "active" or "inactive"
ne_status=$(systemctl is-active nexusedge)

gateway_ip=$(hostname -I|cut -d" " -f1)

# get current timestamp from nodejs as an iso8601 string
timestamp=$(/usr/bin/node -e "console.log(new Date().toISOString())")

# generate a json with the shell variables. -c suppresses newlines.
message_json=$( jq -c -n \
--arg device "nexusedge-gateway" \
--arg gateway_ip "$gateway_ip" \
--arg ne_status "$ne_status" \
--arg received_time "$timestamp" \
--arg device_id "$id"\
'{device: $device, gateway_ip: $gateway_ip, status: $ne_status, _meta: {received_time: $received_time, device_id: $device_id}}' )

# publish data to the linklab influxdb mqtt topic
mosquitto_pub -t gateway-data -m "$message_json"
done
4 changes: 2 additions & 2 deletions scripts/systemd/nexusedge-heartbeat.service
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[Unit]
Description=Send a heartbeat every 5 minutes from a NexusEdge gateway
Description=Send a heartbeat every minute from a NexusEdge gateway
After=linklab-influxdb-publisher.service
Wants=linklab-influxdb-publisher.service

[Service]
# just wait until the linklab mqtt publisher is setup and functioning
ExecStartPre=/bin/sh -c 'sleep 5'
ExecStart=/usr/bin/node /root/on-the-edge/platform/utils/send-heartbeat.js
ExecStart=/root/on-the-edge/scripts/send-ne-status.sh
Restart=always
StandardOutput=syslog
StandardError=syslog
Expand Down

0 comments on commit 046c2c9

Please sign in to comment.