Skip to content

GridlessCompute/Jua-Kali-Serial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bluecollarSerial

This program reads data from a serial port, parses it as JSON, and sends it to a web server running on a Unix socket.

Description

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.

Configuration

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.

Serial Data Format

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.

Building and Running

To build the program, run the following command:

go build -o ~/juakaliSerial

The program will then start reading from the configured serial port and forwarding the data to the specified Unix socket.

Systemd Serivce

  1. Create and edit service file:

    sudo nano /etc/systemd/system/juakaliSerial.service
  2. 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
  3. Enable and start the service:

    sudo systemctl daemon-reload
    sudo systemctl enable juakaliSerial
    sudo systemctl start juakaliSerial
  4. Check if the service is running:

    sudo systemctl status juakaliSerial

Dependencies

This project uses the following Go modules:

  • github.com/tarm/serial for 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.

About

Serial MiddleMan for Bluecollar Core

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages