# API - [GET /api/version](#get-apiversion) - [GET /api/connection/status](#get-apiconnectionstatus) - [GET /api/connection](#get-apiconnection) - [POST /api/connection](#post-apiconnection) - [GET /api/system](#get-apisystem) - [POST /api/system](#post-apisystem) - [GET /api/steps/values](#get-apistepsvalues) - [POST /api/steps/values](#post-apistepsvalues) - [GET /api/triggers/time](#get-apitriggerstime) - [POST /api/triggers/time](#post-apitriggerstime) - [GET /api/triggers/motion](#get-apitriggersmotion) - [POST /api/triggers/motion](#post-apitriggersmotion) - [POST /api/firmware](#post-apifirmware) ## GET /api/version Returns the unique identifier of the chip and the version of the firmware. *Example response:* ```json { "systemID": "st41r", "version": "2.0.0-beta.1+6" } ``` ## GET /api/connection/status Returns the status of the WiFi connections. The value of the 'status' element corresponds to the ```wl_status_t``` enum as defined in [wl_definitions.h](https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/include/wl_definitions.h). *Example response:* ```json { "ap": { "enabled": true, "ip": "192.168.4.1" }, "station": { "enabled": true, "status": 3, "ip": "10.138.1.10" } } ``` ## GET /api/connection Returns the settings of the WiFi connections. *Example response:* ```json { "hostname": "stairs", "accesspoint": true, "station": true, "ssid": "MyWiFi", "password": "12345678", "dhcp": true, "ip": "", "subnetmask": "", "gateway": "" } ``` ## POST /api/connection Updates the settings of the WiFi connections. The module will apply the new settings immediately and will break existing connections. *Example request:* ```json { "hostname": "LivingRoomStairs", "accesspoint": false, "station": true, "ssid": "MyWiFi", "password": "12345678", "dhcp": false, "ip": "10.138.1.100", "subnetmask": "255.255.255.0", "gateway": "10.138.1.1" } ``` ## GET /api/system *Example response:* ```json { "ntpServer": "eu.pool.ntp.org", "ntpInterval": 5, "lat": 52.370216, "lng": 4.895168, "pins": { "ledAP": 4, "ledSTA": 5, "apButton": 2, "pwmSDA": 13, "pwmSCL": 12 }, "pwmAddress": 64, "pwmFrequency": 1600, "mapsAPIKey": "" } ``` ## POST /api/system ## GET /api/steps/values Returns the current brightness value for each step. The number of items in the array is equal to the number of configured steps. Each value has a range of 0 to 255. *Example response:* ```json [ 0, 10, 30, 50, 80, 110, 130, 150, 160, 170, 180, 190, 200, 230, 255 ] ``` ## POST /api/steps/values Changes the brightness value for each step. If the number of values in the array is less than the number of configured steps, each subsequent step is considered to be off. An optional element 'transitionTime' can be included which specifies how long the transition from the current value of each step to it's new value should take, the module will then smoothly fade between the values. The transition time must be specified in milliseconds. Assume a maximum of 30 seconds, because I did not test with higher values. Ain't nobody got time for that! If no transition time or 0 is specified, the new values will be applied immediately. An optional array 'startTime' can be included which specifies the delay, for each step individually, before the transition will start. The example request uses this to create a sweeping effect. If no or not enough values are provided, they are assumed to be 0. *Example request:* ```json { "transitionTime": 500, "values": [ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 ], "startTime": [ 0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700 ] } ``` ## GET /api/triggers/time Returns the current settings for the time triggers. time: Meaning depends on the triggerType | triggerType | description | | ----------- | - | | 0 | fixed time, set time to the number of minutes since midnight | | 1 | relative to sunrise, set time to the number of minutes before or after sunrise to trigger (negative numbers mean before sunrise) | | 2 | relative to sunset, set time to the number of minutes before or after sunset to trigger (negative numbers mean before sunset) | daysOfWeek: Flags determining which days of the week the trigger is active. | value | day | | ----- | --- | | 1 | Monday | | 2 | Tuesday | | 4 | Wednesday | | 8 | Thursday | | 16 | Friday | | 32 | Saturday | | 64 | Sunday | Therefore 127 means every day of the week. brightness: value from 0 to 255 enabled: whether or not this trigger is enabled *Example response:* ```json { "enabled": true, "transitionTime": 1000, "triggers": [ { "time": 480, "daysOfWeek": 127, "brightness": 0, "triggerType": 0, "enabled": true }, { "time": 1200, "daysOfWeek": 127, "brightness": 255, "triggerType": 0, "enabled": true } ] } ``` ## POST /api/triggers/time Changes the time trigger settings. Request body format is the same as is returned in the GET request. If the "triggers" array is omitted entirely, the items will not be cleared or overwritten. ## GET /api/triggers/motion Returns the current settings for the motion triggers. delay: How long to keep the lights on after the last sensor stops detecting motion. pin: GPIO pin to which the motion sensor is connected. High is assumed to be active. direction: Enumeration determining from which side the sweep animation starts if transitionTime is set. | value | description | | ----- | --- | | 1 | Non-directional. All steps change brightness at the same time. | | 2 | Top-down. Starts a sweeping fade from the top step. | | 3 | Bottom-up. Starts a sweeping fade from the bottom step. | brightness: value from 0 to 255 enabled: whether or not this trigger is enabled *Example response:* ```json { "enabled": true, "enabledDuringTimeTrigger": true, "transitionTime": 1000, "delay": 30000, "triggers": [ { "pin": 14, "brightness": 64, "direction": 2, "enabled": true }, { "pin": 15, "brightness": 64, "direction": 3, "enabled": true } ] } ``` ## POST /api/triggers/motion Changes the motion trigger settings. Request body format is the same as is returned in the GET request. If the "triggers" array is omitted entirely, the items will not be cleared or overwritten. ## POST /api/firmware Uploads new firmware. The bin file should be posted as a multipart/form-data file attachment. Name is not relevant.