Feedback & Control over the Cloud
Collect Data. Assign Boundaries. Design Controls.
Enhance the value of data monitoring with timely intervention actions made with local automations or from the cloud dashboard using our Python SDK.
FATBOX G3 Implementation Features
TIME SERIES DATA
With on board RTC you get time-series JSON data that is useful for analytics & AI applications
DEVICE CONTROL
Write to downstream Modbus & CAN Bus devices
PROCESS DATA
Run custom scripts to process data locally on the gateway
Application Example: Monitoring a HVAC facility
We are monitoring a HVAC facility using a Ubidots cloud dashboarsd.
Scripts on the FATBOX G3 will trigger on a fan when the temperature goes beyond a set point. We also included another script to allow users to override & control the fan system from the Ubidots dashboard.
Various other applications of the same logic can be to:
-
helping manage crop conditions in agriculture & urban farming
-
to control energy usage in buildings
-
design for critical intervention to prevent damage to goods, infrastructure or threats to health & safety
How we set it up
Our test rig is set up like this, FATBOX --> Novus Digirail-2R relay --> wall fan
1. Add an entry for the fan (controlled by the relay) in </user/iotasset.txt>
TYPE,R
ADDR,3
MBFC,3
REGS,8,1,UINT16HL
Key,FanState
2. Modify </scripts/ubidots/ubidots_client.py> to react when the FATBOX receives updates to the "fanstate" variable from Ubidots.
In the code snippet below, when '1' (or '0') is received from the Ubidots dashboard, novus_on.lua (or novus_off.lua) is executed and that turns the fan on (or off).
#OPTION User Compute Scripts
time_now = time.time()
if time_now - time_past >= timer_period: #this user section is called every timer_period (in secs)
#USER CODE timed functions HERE
print('\nTIMER! User Functions Run ',time_now)
# TEST read device variable from ubidots
query_variable = "fanstate" #this is cloud side variable setup in Ubidots that used to control the device parameter
query = "curl -X GET -H \"X-Auth-Token:" + ubidots_token + "\" -H \"Content-Type: application/json\" "
query = query + "https://industrial.api.ubidots.com/api/v1.6/devices/" + ubidots_device + "/" + query_variable + "/values/?page_size=1"
print(query) #this is the query URL to retrieve cloud side variable
answer = os.popen(query).read()
json_answer = json.loads(answer)
var_answer = int(json_answer['results'][0]['value']) #cloud side variable is parsed into script variable for further operation
print ('Fanstate:',var_answer)
if (var_answer==1) and (var_last==0):
os.system("lua /scripts/novus_on.lua") #custom user script to swicth a field device e.g. via Modbus RTU register mod
var_last = 1
print("On FAN")
elif (var_answer==0) and (var_last==1):
os.system("lua /scripts/novus_off.lua")
var_last = 0
print("Off FAN")
# END timed functions END
time_past = time.time()
# MAIN loop sleep
time.sleep(0.2)
3. Setup the Ubidots dashboard with a switch widget that directly updates the fanstate variable.
Further Engineer's Notes - Azure cloud users
The downstream Modbus controlled device are triggered by receiving signals from the G3 IoT gateway via the serial/Ethernet port connection. Users will need to add a specific action command that is passed to the script during runtime. Check out also this tutorial from Azure.
For example, below are the action commands currently supported by Azure ‘message-to-device’.
Action Command
MBR,UNITADDR,MBFC,REGSADDR,VALUE
Action Command
MBT,UNITADDR,MBFC,REGSADDR,VALUE
Action
Write value to coil/register of slave unit.
Action
Write value to coil/register of slave unit.
Example
MBR,1,6,8,1
Example
MBT,192.168.1.100:502,6,9,1
MBR=Modbus/RTU over serial port
MBT=Modbus/TCP over Ethernet port
UNITADDR=Address of Modbus unit
MBFC=Modbus function code (5,6,15,16 supported)
REGSADDR=Address of coil/register
VALUE=Write value in decimal number
To run and test your solution on console, enable SSH and log in as ‘root’. We will then need to run the azuremsgbot script with the specific action command:
# python /scripts/python/azuremsgbot.py MBR,1,6,8,1
# python /scripts/python/azuremsgbot.py MBT,192.168.1.100:502,6,9,1
# lua /scripts/azuremsgbot.lua MBR,1,6,8,1
# lua /scripts/azuremsgbot.lua MBT,192.168.1.100:502,6,9,1
To use Azure’s Device Explorer “Messages to Device”, the G3’s Azure IoT needs to be enabled and actively connected to Azure cloud server. This can be verified by looking at the specific device status in Device Explorer’s Management tab.
Clicking the “Send” button will initiate the message to be sent from
Device Explorer à Azure IoT Hub (cloud) à internet à cellular data network à G3 iotclient à runs azuremsgbot trigger à sends signal to Modbus output device à trigger on/off action on Modbus coil
Other useful commands supported by Azure’s “Message to Device” functions.
Action Command
REBOOT
Action
Reboot the G3 Router
Example
REBOOT
Action Command
BLINK
Action
Blinks the signal LEDs on G3
Example
BLINK
We are here to help you.
Contact us for technical support at the following: support@amplified.com.au