Table of Contents
- Using the RCM Hub API for field devices
- Connecting to the network
- Sending sensor data to the gateway
- A complete working example
All the functions that form the RCM Hub field device API begin with RCMHUB_FD_ prefix.
In order to use the RCM Hub API for field devices you must include the "rcm_hub.h" header file
This includes all the necessary components to work with the RCM Hub APIs.
You start by defining a structure (RCMHUBFieldDeviceConnection), that will hold all the information about the RCMHUB field device connection. The structure needs to be initialized using the RCMHUB_FD_Init function.
Once this is done, you're ready to connect to the wireless network.
To connect to the RCM network as a field device your device need to be in wireless range of a gateway or a router. Your device needs to know four things:
- what is the PHY used by the network (there are two options: see RCMPHY)
- what is the network name
- on what physical interface is the RCM module connected
- what is the device role
The PHY and network name must be set to the same values across all communicating devices. This is usually done during device commissioning or at production.
You also need to know, what is the physical interface that your host device uses to connect to the RCM module. It usually is an UART/USART port or a serial/tty port. The IODevice interface that will be used should be provided by the HALFRED port for your hardware platform.
The last thing is to decide if your device will act as a router or as an end-device (see RCMHUBFieldDeviceRole).
To connect to the network call the RCMHUB_FD_Connect function. In the following example we will assume, that the RCM module is connected using USART1 port, the PHY used is 20 kbps DSSS-BPSK, the network name is "demo-net" and we are developing an end-device.
Once you're done networking you should call the RCMHUB_FD_Disconnect function. This closes the wireless connection.
What happens if I don't disconnect?
It won't harm the network. Other devices will notice that your field device stopped collaborating. The RCMHUB_FD_Disconnect function is only required to disable your RCM module locally.
In order to send data to the gateway you need to register your sensors, collect their values and schedule the transmission.
The RCMHUB_FD_RegisterSensor function registers a sensor. Each sensor registered in the RCM Hub library has:
- a name (string)
- a unit (string)
- a value type (integer or float)
Here's an exemplary call:
The value returned is the ID of the registered sensor.
Once your data set is ready, it can be sent using the RCMHUB_FD_SendSensorValues function. This call does two things:
- it prepares one or more packets (RCM messages) to store the whole dataset
- it wakes up the radio module (if necessary) and schedules sending of these packets
- it clears the dataset so you can build one up again
So here is a complete working example of a function/thread that connects to the network, and periodically sends out 2 sensor values:
Generated on Fri Aug 31 2018 10:01:34 for RCM HUB API Library by 1.8.7