Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype a JSON API using ESP8266 Async HTTP server #77

Open
3rwww1 opened this issue Jun 7, 2018 · 9 comments
Open

Prototype a JSON API using ESP8266 Async HTTP server #77

3rwww1 opened this issue Jun 7, 2018 · 9 comments
Assignees
Labels
enhancement New feature or request low priority
Milestone

Comments

@3rwww1
Copy link
Contributor

3rwww1 commented Jun 7, 2018

timebox: 2d

Todo

get the current WiFi status

request: GET /wifi/status
response code: 200 OK
response body:

{
  "state": "CONNECTED",
  "network" : {
    "ssid": "lapaillasse",
    "bssid": "24:a4:3c:9e:d2:84",
    "rssi": -67,
    "security": "WPA2_PSK",
  }
}

scan WiFi networks

request URI: PUT /wifi/scan
response code: 200 OK
response:

[{
  "ssid": "lapaillasse",
  "bssid": "24:a4:3c:9e:d2:84",
  "rssi": -67,
  "security": "WPA2-PSK"
}, {
  "ssid": "erwan-home",
  "bssid": "4f:a6:3c:9c:ff:57",
  "rssi": -67,
  "security": "WPA2-PSK"
}]

list all saved networks

request URI: GET /wifi/saved/
response code: 200 OK
response body:

[{
  "ssid": "erwan-home",
  "bssid": "4f:a6:3c:9c:ff:57",
  "security": "WPA2_PSK",
  "psk": "biohacking",
  "rssi": -73
}, {
  "ssid": "lapaillasse",
  "bssid": "24:a4:3c:9e:d2:84",
  "security": "WPA2-PSK",
  "psk": "va-te-faire-connecter",
  "rssi": -67,
}]

save a new wifi network to the board

request: POST /wifi/saved
request body:

{
  "ssid": "erwan-home",
  "bssid": "4f:a6:3c:9c:ff:57",
  "psk": "va-te-faire-connecter"
}

response code: 201 CREATED
response body:

{
  "ssid": "erwan-home",
  "bssid": "24:a4:3c:9e:d2:84",
  "rssi": -67,
  "psk": "va-te-faire-connecter"
}

forget all WiFi networks

request uri: DELETE /wifi/saved
response code: 204 NO CONTENT

forget one WiFi network

request uri: DELETE /wifi/saved:bssid
response code: 204 NO CONTENT
(edited)

connect to a saved wifi network

request uri: PUT /wifi/saved/:bssid/connect
response code: 202 ACCEPTED
response body:

{
  "attemptId": "0fe239a4-ed8d-49e9-9838-78e764cb111e"
}

SSE

see this link for reference or this one at Mozilla
SSE endpoint: /sse

event: wifiConnectionResult
id: 0fe239a4-ed8d-49e9-9838-78e764cb111e
data: {
data:   "outcome": "FAILURE",
data:   "reason": "AUTH_FAILED"
data: }

https://github.com/me-no-dev/ESPAsyncWebServer

@3rwww1 3rwww1 changed the title Prototype a REST API using ESP8266 http server Prototype a REST API using ESP8266 Async HTTP server Jun 7, 2018
@3rwww1 3rwww1 changed the title Prototype a REST API using ESP8266 Async HTTP server Prototype a JSON API using ESP8266 Async HTTP server Jun 7, 2018
@3rwww1 3rwww1 added this to the sprint 1 milestone Jun 7, 2018
@3rwww1 3rwww1 assigned 3rwww1 and Kameeno and unassigned Kameeno Jun 7, 2018
@trap98 trap98 assigned trap98 and unassigned 3rwww1 Jun 12, 2018
@3rwww1 3rwww1 added enhancement New feature or request low priority labels Jun 13, 2018
@trap98 trap98 self-assigned this Jun 20, 2018
@3rwww1 3rwww1 modified the milestones: sprint 1, sprint 2 Jun 22, 2018
@Kameeno Kameeno self-assigned this Jun 26, 2018
@Kameeno
Copy link
Contributor

Kameeno commented Jun 28, 2018

is done, is available on: http://192.168.4.1/scan
he get an array like that:

[
  {
    "rssi": -85,
    "ssid": "network0",
    "bssid": "00:00:00:00:00:00",
    "channel": 6,
    "secure": 8,
    "hidden": false
  },
  {
    "rssi": -47,
    "ssid": "network1",
    "bssid": "00:00:00:00:00:00",
    "channel": 6,
    "secure": 8,
    "hidden": false
  },
  {
    "rssi": -77,
    "ssid": "network2",
    "bssid": "00:00:00:00:00:00",
    "channel": 6,
    "secure": 8,
    "hidden": false
  },
  {
    "rssi": -68,
    "ssid": "network3",
    "bssid": "00:00:00:00:00:00",
    "channel": 11,
    "secure": 8,
    "hidden": false
  },
  {
    "rssi": -53,
    "ssid": "network4",
    "bssid": "00:00:00:00:00:00",
    "channel": 11,
    "secure": 7,
    "hidden": false
  },
  {
    "rssi": -71,
    "ssid": "network5",
    "bssid": "00:00:00:00:00:00",
    "channel": 11,
    "secure": 8,
    "hidden": false
  },
  {
    "rssi": -77,
    "ssid": "network6",
    "bssid": "00:00:00:00:00:00",
    "channel": 11,
    "secure": 8,
    "hidden": false
  }
]

@nlsdvl
Copy link

nlsdvl commented Jul 16, 2018

the task related to network service publishing/discovery could be split in another ticket (is it already ?)
I've been testing it today, the discovery worked with:
-- gssdp-discovery -m all
-- dns-sd -B
I was able to access the device on the network with http://coolboard-2c3ae84fbe5b.local/ at some point, but this did not work reliably at later attempts.

I am now looking for an appropriate package that can list the service in javascript.

regarding the API, I was able to use the following endpoints with Curl :
/add/wifi
/reset/wifi
/wifi/scan

the API calls did not work with Postman however.

@nlsdvl
Copy link

nlsdvl commented Jul 16, 2018

API calls from JS working fine.

@nlsdvl
Copy link

nlsdvl commented Jul 16, 2018

service discovery working great with: https://github.com/taoyuan/nbonjour

@nlsdvl
Copy link

nlsdvl commented Jul 17, 2018

request: POST /wifi/saved

There is no way to validate the password that the user posts without disconnecting. So a success response means the password is stored successfully. But not that it is a valid password for that network.

@nlsdvl
Copy link

nlsdvl commented Jul 18, 2018

How about PUT & DELETE ? We need to be able to update or delete WiFis ... current @Kameeno implemented a resetWiFi method for that purpose.

@nlsdvl
Copy link

nlsdvl commented Jul 18, 2018

Maybe not a priority, but there's no mention of a /disconnect command. I expect /connect implicitly disconnect if needed. Disconnect would be used to get back to AP mode, or for test/debug purpose.

cc @3rwww1 @Kameeno you guys reading this ?

@nlsdvl
Copy link

nlsdvl commented Jul 18, 2018

I'd expect an error (4xx client error) when asking the board to forget to a Wifi but the board being actually connected to the same wifi. Correct ?

@Kameeno
Copy link
Contributor

Kameeno commented Jul 19, 2018

@nlsdvl yes, i'm not arriving to reconnect to another wifiNetwork without crashing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low priority
Projects
None yet
Development

No branches or pull requests

4 participants