Be RESTUful #169

Closed
opened 2018-07-13 14:23:29 +01:00 by bistory · 5 comments
bistory commented 2018-07-13 14:23:29 +01:00 (Migrated from github.com)

Hi,

First thanks for your work on this plugin, it is awesome and I use it everyday !
I started to look at integrated it to Home-Assistant but it looks like the format of the API is not RESTful at all :(
Here is the format it should adopt to be compliant :

Create a endpoint /plugin/enclosure/outputs to replace /plugin/enclosure/getOutputStatus
Create /plugin/enclosure/outputs/{OUTPUT_ID} to replace /plugin/enclosure/setIO
=> When sending a GET request to this endpoint, it should send the status of the output
=> When sending a POST request to this enpoint, it should set the status out the output

The same applies to /plugin/enclosure/setEnclosureTempHum
Create /plugin/enclosure/temperature/{OUTPUT_ID}
POST will set the value

And so on with other endpoints :)

It would be cleaner and more standard, that will make it work with every RESTful clients natively.
It doesn't seem to be a difficult mod so I could make a pull request but I would like to be sure you agree with these changes :)

Thanks

EDIT : Using SimpleApiPlugin might even simplify the current API ;)

Hi, First thanks for your work on this plugin, it is awesome and I use it everyday ! I started to look at integrated it to Home-Assistant but it looks like the format of the API is not RESTful at all :( Here is the format it should adopt to be compliant : Create a endpoint /plugin/enclosure/outputs to replace /plugin/enclosure/getOutputStatus Create /plugin/enclosure/outputs/{OUTPUT_ID} to replace /plugin/enclosure/setIO => When sending a GET request to this endpoint, it should send the status of the output => When sending a POST request to this enpoint, it should set the status out the output The same applies to /plugin/enclosure/setEnclosureTempHum Create /plugin/enclosure/temperature/{OUTPUT_ID} POST will set the value And so on with other endpoints :) It would be cleaner and more standard, that will make it work with every RESTful clients natively. It doesn't seem to be a difficult mod so I could make a pull request but I would like to be sure you agree with these changes :) Thanks EDIT : Using SimpleApiPlugin might even simplify the current API ;)
vitormhenrique commented 2018-07-13 16:58:42 +01:00 (Migrated from github.com)

Hello @bistory
I have no problem with the proposed changes, the current implementation was actually someone's pull requested kind of hacked together, to use as API, the initial implementation was not "thought" to be used as an external API, I overlooked that big time...
If you want to work on it go for it! I can help with code review and testing.
Right now I don't have the time to stop and actually implement everything, but I don't have anything against the proposed changes.

Hello @bistory I have no problem with the proposed changes, the current implementation was actually someone's pull requested kind of hacked together, to use as API, the initial implementation was not "thought" to be used as an external API, I overlooked that big time... If you want to work on it go for it! I can help with code review and testing. Right now I don't have the time to stop and actually implement everything, but I don't have anything against the proposed changes.
Baumi1245 commented 2018-12-12 14:36:07 +00:00 (Migrated from github.com)

I would also need a REST-Api for the temperature-readings of my DHT22s to impliment them to openHAB.

Thank you....

I would also need a REST-Api for the temperature-readings of my DHT22s to impliment them to openHAB. Thank you....
anthonyst91 commented 2018-12-12 14:44:50 +00:00 (Migrated from github.com)

The API are not REST-ful but it is not really a problem.
You can get the whole plugin configuration from http://docs.octoprint.org/en/master/api/settings.html

And retrieve the updated informations from the websocket (/sockjs/websocket). The different messages look like the following:

{"plugin": {"data": {"rpi_output_neopixel": [{"color": "rgb(0,0,0)", "auto_shutdown": false, "index_id": 15, "auto_startup": false}], "rpi_output_pwm": [], "rpi_output_temp_hum_ctrl": [{"status": true, "auto_shutdown": true, "index_id": 16, "auto_startup": false}, {"status": false, "auto_shutdown": true, "index_id": 17, "auto_startup": false}], "rpi_output_regular": [{"status": 1, "auto_shutdown": true, "index_id": 1, "auto_startup": true}, {"status": false, "auto_shutdown": true, "index_id": 9, "auto_startup": true}, {"status": 1, "auto_shutdown": true, "index_id": 10, "auto_startup": true}]}, "plugin": "enclosure"}}

{"plugin": {"data": {"sensor_data": [{"index_id": 2, "temperature": 0.0, "humidity": 0.0}]}, "plugin": "enclosure"}}

{"plugin": {"data": {"set_temperature": [{"set_temperature": 124.0, "index_id": 16}, 124.0, {"set_temperature": 30.0, "index_id": 17}, 30.0]}, "plugin": "enclosure"}}

{"plugin": {"data": {"filament_sensor_status": []}, "plugin": "enclosure"}}

Indeed the other API from this plugins are all GET but you can execute all the actions you need without any problem, whatever happens ;)

The API are not REST-ful but it is not really a problem. You can get the whole plugin configuration from [http://docs.octoprint.org/en/master/api/settings.html](/api/settings) And retrieve the updated informations from the websocket (/sockjs/websocket). The different messages look like the following: {"plugin": {"data": {"rpi_output_neopixel": [{"color": "rgb(0,0,0)", "auto_shutdown": false, "index_id": 15, "auto_startup": false}], "rpi_output_pwm": [], "rpi_output_temp_hum_ctrl": [{"status": true, "auto_shutdown": true, "index_id": 16, "auto_startup": false}, {"status": false, "auto_shutdown": true, "index_id": 17, "auto_startup": false}], "rpi_output_regular": [{"status": 1, "auto_shutdown": true, "index_id": 1, "auto_startup": true}, {"status": false, "auto_shutdown": true, "index_id": 9, "auto_startup": true}, {"status": 1, "auto_shutdown": true, "index_id": 10, "auto_startup": true}]}, "plugin": "enclosure"}} {"plugin": {"data": {"sensor_data": [{"index_id": 2, "temperature": 0.0, "humidity": 0.0}]}, "plugin": "enclosure"}} {"plugin": {"data": {"set_temperature": [{"set_temperature": 124.0, "index_id": 16}, 124.0, {"set_temperature": 30.0, "index_id": 17}, 30.0]}, "plugin": "enclosure"}} {"plugin": {"data": {"filament_sensor_status": []}, "plugin": "enclosure"}} Indeed the other API from this plugins are all GET but you can execute all the actions you need without any problem, whatever happens ;)
Baumi1245 commented 2018-12-12 15:21:45 +00:00 (Migrated from github.com)

Sry... can´t find any data here: (http://>IP</api/settings?apikey=>KEY<)
Temperature at the WEB-UI is showing up correct.

`

2  
action_type "output_control"
controlled_io 1
controlled_io_set_value "low"
ds18b20_serial ""
edge "fall"
filament_sensor_enabled true
filament_sensor_timeout 120
gpio_pin "17"
index_id 5
input_pull_resistor "input_pull_up"
input_type "temperature_sensor"
label "Input 5"
printer_action "filament"
temp_sensor_address ""
temp_sensor_humidity 0
temp_sensor_navbar true
temp_sensor_temp 0
temp_sensor_type "22"
use_fahrenheit false
`
Sry... can´t find any data here: (http://>IP</api/settings?apikey=>KEY<) Temperature at the WEB-UI is showing up correct. ` 2 |   -- | -- action_type | "output_control" controlled_io | 1 controlled_io_set_value | "low" ds18b20_serial | "" edge | "fall" filament_sensor_enabled | true filament_sensor_timeout | 120 gpio_pin | "17" index_id | 5 input_pull_resistor | "input_pull_up" input_type | "temperature_sensor" label | "Input 5" printer_action | "filament" temp_sensor_address | "" temp_sensor_humidity | 0 temp_sensor_navbar | true temp_sensor_temp | 0 temp_sensor_type | "22" use_fahrenheit | false `
Baumi1245 commented 2018-12-12 18:09:29 +00:00 (Migrated from github.com)

ok... something strange:
the second sensor is showing 24.7 ° at /api/settings

if i refresh the web-ui the data from /api/settings is shown first (0° and 24.7°) after a short time the correct temperature is appearing in the web-ui.

data in /api/settings is not changing.

ok... something strange: the second sensor is showing 24.7 ° at /api/settings if i refresh the web-ui the data from /api/settings is shown first (0° and 24.7°) after a short time the correct temperature is appearing in the web-ui. data in /api/settings is not changing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Gandalf/OctoPrint-Enclosure#169