This program reads data from a serial port, parses it as JSON, and sends it to a web server running on a Unix socket.
bluecollarSerial is a Go program designed to act as a bridge between a serial device and a web application.
It continuously reads data from a specified serial port, expecting each line to be a JSON object.
This JSON data is then forwarded to a web server via an HTTP POST request to a Unix socket.
The program is configurable via a JSON file located at ~/.config/juakaliSerial/config.json.
If this file does not exist a default configuration will be created.
The configuration file should be a JSON file with the following structure:
{
"unix-socket": "/tmp/bluecollar.sock",
"serial-port": "/dev/ttyUSB0",
"baud-rate": 9600
}unix-socket: The path to the Unix socket the web server is listening on.serial-port: The path to the serial port to read from.baud-rate: The baud rate for the serial communication.
The program expects the serial device to send data as a stream of JSON objects, with each object on a new line. The JSON object should have the following structure:
[
{
"device": 0,
"value": 123.45
}
]device: An integer representing the device ID.value: A float representing the value read from the device.
To build the program, run the following command:
go build -o ~/juakaliSerialThe program will then start reading from the configured serial port and forwarding the data to the specified Unix socket.
-
Create and edit service file:
sudo nano /etc/systemd/system/juakaliSerial.service
-
Add the following to the file:
[Unit] Description=Jua kali serial service After=network.target [Service] ExecStart=/home/{USER_NAME}/juakaliSerial Type=simple Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target -
Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable juakaliSerial sudo systemctl start juakaliSerial -
Check if the service is running:
sudo systemctl status juakaliSerial
This project uses the following Go modules:
github.com/tarm/serialfor serial communication.github.com/gin-gonic/gin(and its dependencies) for web server interaction, although it's only used for the http client in this case.