First of all, what is a gateway used for? It’s simply a device that can provide an Internet connection to an asset or a group of assets not connected to the Internet.
This is what offers the TRB 145 and 142 from Teltonika:
- TRB 145: allow to connect an asset equipped with RS 485 port
- TRB 142: allow to connect an asset equipped with RS 232 port
What do we like about those two:
- the design: simple and robust
- a stable and reliable power supply 9-30 V DC
- the possibility to plug a battery BAT120
- bonus: the rack DIN option to plug it in an electrical table
How to use those gateways? If you want to push data from an automata, it’s quite simple:
- connect the TRB to the serial (485 or 232)
- configure the serial port in read mode
- read the data
- send the data to BAG·Tower
- go back to step 1 for continuous monitoring
Here is a code sample that reads the RS 485 or 232 serial port and sends the data to BAG·Tower.
#!/bin/sh
API_KEY=__ASSET_API_KEY__
# Set serial port parameters
SERIAL_PORT="/dev/ttyRS485-0"
BAUD_RATE="9600"
TIMEOUT="10"
# Configure the serial port
stty -F $SERIAL_PORT $BAUD_RATE cs8 -cstopb -parenb
# Send the command to the RS-485 device (replace 'YOUR_COMMAND_HERE' with your actual command)
echo -n "YOUR_COMMAND_HERE" > $SERIAL_PORT
# Capture the response into a string
read_value=$(timeout $TIMEOUT cat $SERIAL_PORT)
# Send the captured data to an API using curl
curl -s -X POST "https://api.bagtower.bag-era.fr/v2/logs" -H "Content-Type: application/json" -H "x-api-key: $API_KEY" -d "data=$read_value"
echo "Data sent to the BAG·Tower!"
To continuously send the data, you can put this script in a crontab
Here is the crontab to send the data every 10 minutes
*/10 * * * * /usr/bin/sh /bin/sh /root/push_bagtower.sh