Read time-series data, using serial communication over USB
, for your externally connected Arduino device and attached Arduino shield; afterwords, share your data through gRPC
.
Currently this server only supports the following shield:
Example: SparkFun Weather Shield monitoring dutifully a red mulberry seedling, the code is powered by this code repository - read more via this blog post.
Imagine having purchased multiple measuring instruments for an IoT project, for example: pressure monitor, temperature probe, multi-sensor reader, etc. Each sensor provides different measured data - Is it possible to create a simple get data from device interface to abstract all implantation detail and provide an easy-to-use API?
Imagine having built an application which can provide an easy-to-use API for multiple hardware sensors. How do you make the API accessible between one or many applications running concurrently? How do you make this API accessible either locally and or remotely?
treader-server
tries to provide an easy-to-use interface for you to connect many interprocess communication requests either locally on your computer or remotely across the internet or your network.
To run this code, you need the following:
- You need an Arduino device.
- You need to have the Arduino device running either one of the following code:
- The computer running this server needs to be connected to the Arduino device over
serial communication
USB port. - The computer running this server needs to know the port address of your externally connected Arduino. Please find out what USB port your external device is connected on. Note: please replace
/dev/cu.usbmodem14201
with the value on your machine, a Raspberry Pi would most likely have the value/dev/ttyACM0
.
This server starts by connecting to the Arduino device, warms up sensors if necessary and runs continuously waiting for you to make gRPC requests.
When you make a gRPC request, this server will pull data from the external device and send you back a gRPC response. You do what you want with the data.
Your application must implement the Telemetry
service definition found here. The service definition code snippet is as follows:
service Telemetry {
rpc GetTimeSeriesData (google.protobuf.Empty) returns (stream TelemetryDatum) {}
}
message TelemetryLabel {
string name = 1;
string value = 2;
}
message TelemetryDatum {
string metric = 1;
repeated TelemetryLabel labels = 2;
double value = 3;
google.protobuf.Timestamp timestamp = 4;
}
The Arduino platform has a wonderful ecosystem of open-source hardware with libraries. The goal is to take advantage of the libraries the hardware manufacturers wrote and not worry about the complicated implementation details; nor conflicting non-open source licensing agreements.
-
You want to focus on writing software or web-applications utilizing IoT sensors, not focus low-level hardware code.
-
You want to treat the sensor like a micro-service.
-
You want to use Golang.
No problem, you can help change that by contributing via pull requeests code for any sensors you think this project should have. If you are looking for a specific sensor, create a request issue.
The following project is currently using this project:
- tpoller-server - Application written in Go which polls Time-series data at specific intervals and saves to persistent storage
- tstorage-server - Fast time-series data storage server accessible over gRPC
- sparkfunweathershield-arduino - Application implemented in C++ which measures time-series data from the SparkFun Weather Shield board and provides serial usb interface for other devices
If you want to add your own, feel free to make a PR.
Install the application.
go install github.com/bartmika/treader-server@latest
Run our server continuously in the foreground:
$GOBIN/treader-server serve -f="/dev/cu.usbmodem14401" -s="SPARKFUN-DEV-13956" -p=50052
If your console output looks as the following then the application has been successfully started. You are ready to use the service!
2021/07/15 22:00:16 READER: Attempting to connect Arduino device...
2021/07/15 22:00:16 READER: Waiting for Arduino external sensors to warm up
2021/07/15 22:00:26 gRPC server is running.
The sub-command details are as follows:
Run the gRPC server to allow other services to access the time-series data reader
Usage:
treader-server serve [flags]
Flags:
-f, --arduino_path string The location of the connected arduino device on your computer. (default "/dev/cu.usbmodem14201")
-s, --arduino_shield string The shield hardware attached to the arduino. (default "SPARKFUN-DEV-13956")
-h, --help help for serve
-p, --port int The port to run this server on (default 50052)
Please note for arduino_shield
the only supported values are:
SPARKFUN-DEV-13956
for sparkfunweathershield-arduino code repo.
If you'd like to setup the project for development. Here are the installation steps:
-
Go to your development folder.
cd ~/go/src/github.com/bartmika
-
Clone the repository.
git clone https://github.com/bartmika/treader-server.git cd treader-server
-
Install the package dependencies
go mod tidy
-
In your terminal, make sure we export our path (if you haven’t done this before) by writing the following:
export PATH="$PATH:$(go env GOPATH)/bin"
-
Run the following to generate our new gRPC interface. Please note in your development, if you make any changes to the gRPC service definition then you'll need to rerun the following:
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/telemetry.proto
-
You are now ready to start the server and begin contributing!
go run main.go serve -f="/dev/cu.usbmodem14401" -s="SPARKFUN-DEV-13956" -p=50052
Found a bug? Need Help? Please create an issue.
ISC License © Bartlomiej Mika