Records and displays temperatures gathered from a Raspberry Pi through the use of Vktech DS18b20 temperature sensors.
- JDK 7
- Maven 3
- Wire up the temperature sensors to your Raspberry Pi and run the following commands:
sudo modprobe w1-gpio
sudo modprobe w1-therm
- Checkout the project:
git clone https://github.com/DWiechert/pi-temperature.git
- Build the project:
mvn clean install -Dmaven.test.skip
- SCP the built war
<project-directory>/target/pi-temperature-<version>.war
onto your Raspberry Pi. - Start the war:
sudo java -jar pi-temperature-<version>.war
To check the installation and setup were successful, there is a hello-world
REST endpoint to test with:
curl <raspberry-pi-ip>:8080/hello-world
Endpoint | Method | Variables | Example | Description |
---|---|---|---|---|
/sensors/list |
GET | None | curl <raspberry-pi-ip>:8080/sensors/list |
Returns a list of all Sensors and their information - name, serialId, tempC, tempF. |
/sensors/list/<name> |
GET | None | curl <raspberry-pi-ip>:8080/sensors/list/<name> |
Returns the specified Sensor and its information - name, serialId, tempC, tempF. |
/sensors/name/<serialId> |
PUT | <serialId> |
curl -X PUT -d "Some name" <raspberry-pi-ip>:8080/sensors/name/<name> |
Updates the provided sensor with a user-friendly name. |
- By default, sensors are read every minute and update the alerts that are currently set on. The time between sensor reads can be overridden by providing the
sensorScanSchedule
property in theapplication.properties
file. The sensor scan schedules use the Quartz Cron Expressions. Example of overridding the schedule to read every 10 seconds:
sensorScanSchedule=0/10 * * * * ?
- By default, sensors are read from the directory
/sys/bus/w1/devices/w1_bus_master1/
. The sensors directory can be overridden by providing thesensorsMasterDirectory
property in theapplication.properties
file. Example of overridding the sensors directory:
sensorsMasterDirectory=S:\\sensors\\
Endpoint | Method | Variables | Example | Description |
---|---|---|---|---|
/alerts/list |
GET | None | curl <raspberry-pi-ip>:8080/alerts/list |
Returns a list of all Alerts and their status (on or off). |
/alerts/list/<name> |
GET | None | curl <raspberry-pi-ip>:8080/alerts/list/<name> |
Returnsthe specific Alert and its status (on or off). |
/alerts/setOn/<name> |
PUT | <name> - The name of the alert. |
curl -X PUT <raspberry-pi-ip>:8080/alerts/setOn/<name> |
Turns the specified alert on. |
/alerts/setOff/<name> |
PUT | <name> - The name of the alert. |
curl -X PUT <raspberry-pi-ip>:8080/alerts/setOff/<name> |
Turns the specified alert off. |
/alerts/update/<name> |
PUT | <name> - The name of the alert. |
curl -X PUT -d "Some message" <raspberry-pi-ip>:8080/alerts/update/<name> |
Updates the specified alert with the provided message. |
This alert writes the sensor data to a csv file. The alert name is CsvAlert
and the supported update information is:
Variable | Type | Default |
---|---|---|
filename | String | sensor-data.csv |
delimiter | char | , |
An example of updating this alert to write to a file called something.csv
with a delimiter of @
is:
curl -X PUT -d {\"filename\":\"something.csv\",\"delimiter\":\"@\"} <raspberry-pi-ip>:8080/alerts/update/CsvAlert