-
Notifications
You must be signed in to change notification settings - Fork 1
API
A rudimentary REST API is available for configuring and getting data from
Hoplite. The default config listens on all IPs at port 5000, but a specific
listener IP and port can be specified using the --api
parameter when
starting Hoplite.
The following examples assume that curl is running on the same host as the Hoplite server.
pi@hoplite:~ $ curl -X GET -s http://127.0.0.1:5000/v1/ | jq
{
"code": 200,
"data": {
"v1": {
"display": "st7735",
"hx_list": [
{
"channels": {
"A": {
"co2": false,
"name": "American Wheat",
"offset": 297569.1111111111,
"refunit": 21.189888888888877,
"size": "corny",
"tare": 4,
"volume": 18.9,
"weight": 4610
}
},
"dout": 5,
"pd_sck": 6
},
{
"channels": {
"A": {
"co2": true,
"name": "CO2",
"offset": 128814.44444444444,
"refunit": 21.39255555555556,
"size": "custom",
"tare": 4.82,
"volume": 2.27,
"weight": 5921
}
},
"dout": 12,
"pd_sck": 13
}
],
"temp": 0,
"weight_mode": "as_kg_net"
}
},
"message": null,
"status": "ok"
}
curl -X GET -v -s http://127.0.0.1:5000/v1/hx/<index>/
where <index>
is the index of the sensor you want to get. The previous
command lists the sensors in order, so you can either count the entries from
that command, or just spam curl and increment the index until you get the
entry you're after.
curl -X GET -v -s http://127.0.0.1:5000/v1/hx/<index>/<channel>/
where <index>
is as described above, and <channel>
is either
A or B. The HX711 module supports two channels for attached load cells.
curl -X GET -v -s http://127.0.0.1:5000/v1/hx/<index>/<channel>/<attribute>/
where <index>
and <channel>
are as described above, and
<attribute>
is one of the attributes of the channel.
pi@hoplite:~ $ curl -X PUT -H "Content-Type: application/json" -d '{"name": "Bud Light"}' -s http://127.0.0.1:5000/v1/hx/0/A/name
{
"code": 200,
"data": {
"name": "Bud Light"
},
"message": "name successfully updated",
"status": "ok"
}
Useful for updating names, keg sizes, etc. though that can be done via the web interface as well.
pi@hoplite:~ $ curl -X POST -H "Content-Type: application/json" -d '{"pd_sck": 27, "dout": 17, "channels": { "A": {"name": "Yuengling", "size": "custom", "tare": 9.7, "volume": 29.3} } }' -s http://127.0.0.1:5000/v1/hx/
{
"code": 200,
"data": {
"0": {
"channels": {
"A": {
"co2": false,
"name": "Yuengling",
"offset": 0,
"refunit": 0,
"size": "custom",
"tare": 9.7,
"volume": 29.3
}
},
"dout": 17,
"pd_sck": 27
}
},
"message": "Index 0 successfully created or updated",
"status": "ok"
}
This is how you get started, by adding your first HX711 and one or both
channels. The message
field of the response will contain the index
that you just created, as well as the data
field.
pi@hoplite:~ $ curl -X POST -H "Content-Type: application/json" -d '{"name": "Yuengling", "size": "custom", "tare": 9.7, "volume": 29.3}' -s http://127.0.0.1:5000/v1/hx/0/B
{
"code": 200,
"data": {
"B": {
"co2": false,
"name": "Yuengling",
"offset": 0,
"refunit": 0,
"size": "custom",
"tare": 9.7,
"volume": 29.3
}
},
"message": "B successfully created or updated",
"status": "ok"
}
Similar to above, except you need to specify the index and channel you are targeting.
pi@hoplite:~ $ curl -X DELETE -s http://127.0.0.1:5000/v1/hx/0/
{
"code": 200,
"data": {
"0": {
"channels": {
"A": {
"co2": false,
"name": "Yuengling",
"offset": 0,
"refunit": 0,
"size": "custom",
"tare": 9.7,
"volume": 29.3
},
"B": {
"co2": false,
"name": "Yuengling",
"offset": 0,
"refunit": 0,
"size": "custom",
"tare": 9.7,
"volume": 29.3
}
},
"dout": 17,
"pd_sck": 27
}
},
"message": "0 successfully deleted",
"status": "ok"
}
The DELETE
action will return the deleted data, just in case you got the
wrong index and need to re-add it.
pi@hoplite:~ $ curl -X DELETE -s http://127.0.0.1:5000/v1/hx/0/B/
{
"code": 200,
"data": {
"B": {
"co2": false,
"name": "Yuengling",
"offset": 0,
"refunit": 0,
"size": "custom",
"tare": 9.7,
"volume": 29.3
}
},
"message": "B successfully deleted",
"status": "ok"
}
The DELETE
action will return the deleted data, just in case you got the
wrong index or channel and need to re-add it.