robotology / assistive-rehab

Assistive and Rehabilitative Robotics
https://robotology.github.io/assistive-rehab/doc/mkdocs/site
BSD 3-Clause "New" or "Revised" License
20 stars 11 forks source link

Get acquainted with the wifi button #264

Closed vvasco closed 4 years ago

vvasco commented 4 years ago

For now, I didn't have much success with the wifi button. I need to understand how to make it visible when I connect it to the laptop (it only seems to recharge) and get acquainted with the REST API. I'll report here any progress I'm going to do.

vvasco commented 4 years ago

Today I successfully managed to connect the button to R1 wifi and to make it visible from my laptop. I summarize here the steps I followed:

  1. I manually opened the button and removed the battery, as myStrom support suggested. This was not sufficient to completely reset the button, since I had to reset it by keeping it pressed for 10 seconds and leave it within 5 seconds. The button blinked 10 times white, which means that the reset was successful.

  2. I used the myStrom app on my phone to connect the device to R1 wifi. I managed to connect it.

  3. I connected the device to my laptop using the provided usb cable. According to the instructions, we have to listen to the udp port 7979, so I run the command nc -lvu 7979 and got the following reply:

    Listening on [0.0.0.0] (family 0, port 7979)
    Connection from myStrom-Button-D02577.r1.local 7979 received!

Note: according to the instructions, we don't need to configure the button in the myStrom app, so step 2 should'n be necessary. I tried also to avoid step 2, but the button did not become not visible on my laptop.

Now I am trying to send requests to the button through the REST API. I tried to send a GET request to receive the device information, as described here, but I get the following error:

Note: Unnecessary use of -X or --request, GET is already inferred.
*   Trying 192.168.100.158...
* TCP_NODELAY set
* connect to 192.168.100.158 port 80 failed: Connection refused
* Failed to connect to 192.168.100.158 port 80: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 192.168.100.158 port 80: Connection refused

I'll investigate more on this, to understand why it happens and how to solve it.

vvasco commented 4 years ago

I used a different button (same type) and I tried to configure it with the wifi of my house, following the procedure I described. I managed to configure it and to successfully send a GET request to have the device information. I sent this request: curl -v --location --request GET '192.168.1.115/api/v1/device'

and got the following output:

*   Trying 192.168.1.115...
* TCP_NODELAY set
* Connected to 192.168.1.115 (192.168.1.115) port 80 (#0)
> GET /api/v1/device HTTP/1.1
> Host: 192.168.1.115
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Pragma: no-cache
< Cache-Control: no-store, no-cache
< Content-Type: application/json
< Content-Length: 338
< Connection: close
< 
{
    "68C63AD1E83D": {"type": "button", "battery": true, "reachable": true, "meshroot": false, "charge": true, "voltage": 4.083, "fw_version": "2.74.11", "single": "", "double": "", "long": "", "touch": "", "generic": "", "connectionStatus": {"ntp": false, "dns": true, "connection": true, "handshake": true, "login": true}, "name": ""}
* Closing connection 0

Unfortunately, I tried to send a different GET request :

curl --location --request GET 'http://192.168.1.115/api/v1/action/single' and I got again Connection refused:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (7) Failed to connect to 192.168.1.115 port 80: Connection refused

Now every request that I send produces a connection refused output. I contacted the myStrom support and I'm waiting for their response.

vvasco commented 4 years ago

The myStrom support replied that in order to optimize the battery, after a press the button goes directly into sleep mode, causing the Connection Refused message (I think there is a timeout of few minutes). However, this is only relevant for us when configuring the button, which should happen only once.

I successfully managed to configure the button in order to send:

To test if I am able to receive requests when pressing the button, I created a node.js script which:

This shows the functionality: ezgif com-video-to-gif (2)

The terminal at the bottom is just to check if I receive the start / stop commands on the RPC port. The terminal on the top shows the output of the node.js script:

Note: To keep track, in order to configure an action we can run the following command in a terminal:

curl -v -d "single=post://192.168.100.139:8080/api/mystrom?key%3Dstart" http://192.168.100.158/api/v1/device/68C63AD02577

This configures the action single (i.e. press once) to send a POST request to a machine with IP address 192.168.100.139 on port 8080, with the payload key=start.