[HowTo] [updated] Install the WIO Server on Raspberry Pi 3

[size=200]Raspberry Pi 3: WIO Link Server installation into the filesystem[/size]
see also github.com/Seeed-Studio/Wio_Lin … filesystem

Within the graphical UI configure Wifi, IP, Hostname. In “Add/Remove Software” search for “Apache” and install “Apache HTTP Server”.

You can set the Raspi to boot into command line only now, we don’t need the GUI anymore

All the following instructions you can perform on the command line or better within an SSH client of you choice (ie. PuTTY).

Just because I’m used to work with VIM:

sudo apt-get install vim

[size=150]1. Configure SSL[/size]
See also digitalocean.com/community/ … untu-14-04

sudo a2enmod ssl sudo service apache2 restart sudo mkdir /etc/apache2/ssl

Make sure, that you enter your (local) domain name at “Common name (FQDN), for example “*.se38.local”

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

Enter your domain name and the created key files:

sudo vim /etc/apache2/sites-available/default-ssl.conf

<IfModule mod_ssl.c> <VirtualHost _default_:443> ServerAdmin admin@example.com ServerName se38-wio-1.se38.local DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine on SSLCertificateFile /etc/apache2/ssl/apache.crt SSLCertificateKeyFile /etc/apache2/ssl/apache.key

sudo a2ensite default-ssl.conf sudo service apache2 restart

[size=150]2. Enable reverse-proxy for https and wss[/size]

sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod proxy_wstunnel

sudo vim /etc/apache2/sites-available/default-ssl.conf 

Insert at the end (but before )

[code] BrowserMatch “MSIE [17-9]” ssl-unclean-shutdown

        ProxyRequests Off
        ProxyPreserveHost On
        <Proxy *>
                 Order deny,allow
                Allow from all
        </Proxy>

        ProxyPass /v1/node/event ws://127.0.0.1:8080/v1/node/event
        ProxyPassReverse /v1/node/event ws://127.0.0.1:8080/v1/node/event

        ProxyPass /v1 http://127.0.0.1:8080/v1
        ProxyPassReverse /v1 http://127.0.0.1:8080/v1[/code]

Again:

sudo service apache2 restart

[size=150]3. ESP8266 cross-compile toolchain[/size]

(the filename in this example only belongs to the Raspberry Pi with ARM processor. For other Linux installations you have to search for the right file in this JSON document arduino.esp8266.com/package_esp8 … index.json )

cd /opt sudo wget http://arduino.esp8266.com/linuxarm-xtensa-lx106-elf-g46f160f.tar.gz sudo tar -zxvf linuxarm-xtensa-lx106-elf-g46f160f.tar.gz sudo vim /etc/profile
-> add the following to the path definitions

:/opt/xtensa-lx106-elf/bin

Restart the Raspi or enter

export PATH=$PATH:/opt/xtensa-lx106-elf/bin

[size=150]4. Install the Python Server[/size]

sudo apt-get install python-dev sudo pip install tornado sudo pip install tornado-cors sudo pip install PyJWT sudo pip install pycrypto sudo pip install PyYaml

[size=150]5. Install the Wio Server[/size]

cd /opt sudo git clone https://github.com/Seeed-Studio/Wio_Link.git sudo chown -R pi:users Wio_Link cd Wio_Link sudo git clone https://github.com/Seeed-Studio/Grove_Drivers_for_Wio.git rm grove_drivers/ -R mv Grove_Drivers_for_Wio grove_drivers sudo chown -R pi:users grove_drivers rm grove_drivers/.git -R -f rm grove_drivers/.gitignore -R -f

[size=150]6. Start the Server [/size]

python ./server.py

Compile the Grove Drivers

python ./scan_drivers.py

Test

python ./build_firmware.py

[size=150]7. Autostart the Server[/size]

sudo vim /etc/rc.local

at the end but before “exit 0”

su pi -c 'cd /opt/Wio_Link && python ./server.py'

Reboot

[size=150]Update[/size]
If you’re starting the server automatically as described in chapter 7 you may get a compile error while updating the firmware via mobile App.
wio.png
In this case you have to uncomment the entry (set a ‘#’ in front of the line) in file /etc/rc.local again, reboot and start the server “by hand”:

cd /opt/Wio_Link python server.py
Update the firmware via App and let the server autostart again as described in chapter 7.

It is really coooooool !!!

This is fantastic! I would like to do the same using Beaglebones Green. Spent all morning on it but did not achieve the outcome I wanted. Tried both thin and full versions. I would recommend that this become a product or support item on a downloadable img file or on a uSD card. There are too many steps (Server Deployment Guide: github.com/Seeed-Studio/Wio_Lin … -frond-end) to follow in the guide and even some are left out: eg installing docker. For beginners it is too difficult but this is one of the most important resources for anyone wanting a long term investment in WioLink. I have just experienced another company, Ninja Blocks going bankrupt and this week closed its cloud service so having an alternative as a contingency to the cloud is important. When Ninja Blocks closed off their cloud service many customers where left high & dry and their investment collapsed.

Hi Philip,
my solution works without Docker (as described in chapter 2 of the official installation guide).
It should also work with other Linux distributions (tested with Ubunto Server 64bit). You only have to change the “ESP8266 cross-compile toolchain” file.

If you would distribute an image or uSD card you would have an outdated system soon, because the server and drivers are updated often on github.

A good idea would be a proper automated installation script though …

I love it. The API request must be really faster.

Hi, first of all, great tutorial!

I was able to successfully run the server, scan drivers, build the firmware.
Unfortunately I cannot convince my Wio Links to connect to the local server.

After entering the Wifi information (via android or via wio-cli), i run in a timeout. The Wio seems to connect to Wifi successfully (blue LED turns from blinking twice to blinking once), but then fails connecting to the server.

Some further information:

  • I can login / register to the new server
  • There seem to be no requests from Wio to the server (according to the apache access/error logs)
  • I even tried to use Let’s Encrypt certificates (to exclude possible ssl cert validation errors)
  • International server works without issues

Any help highly appreciated!
Kai

Hello Kai,
do you see a different behaviour of the blue LED if you connect to the international server and your own server? It should blink every second.

Try the following:
stop the automatic start of the server by editing the file “/etc/rc.local” again. Delete the inserted line or comment out by putting a hash (#) in front of the line.

Restart the PI and enter

cd /opt/Wio_Link python server.py

Ther server should start now and you should see the communication, for example

[I 160430 10:13:30 server:535] SQLite version: 3.8.7.1 [I 160430 10:13:32 server:432] xchange device server accepted conns: 1 [I 160430 10:13:32 server:136] accepted sn: {your serial number here} @fw_version 1.1 [I 160430 10:13:32 server:165] valid hello packet from node 104 [I 160430 10:13:32 server:429] ota device server accepted conns: 1 [I 160430 10:13:32 server:136] accepted sn: {your serial number here} @fw_version 1.1 [I 160430 10:13:32 server:165] valid hello packet from node 104 [I 160430 10:14:32 server:306] heartbeat sent to node 104 on xchange channel [I 160430 10:14:32 server:306] heartbeat sent to node 104 on ota channel [I 160430 10:14:32 server:224] Node 104 alive on xchange channel! [I 160430 10:14:32 server:228] Node 104 recv json on ota channel

Or do you see any error messages?

Hi,

thanks for your quick response!

I am already starting the server manually. This is the output:

  • When creating new wio link node:
    [I 160430 12:35:23 handlers:86] get current user, id: 26, email: <>
    [I 160430 12:35:23 web:1946] 200 POST /v1/nodes/create?name=node000&board=Wio+Link+v1.0 (127.0.0.1) 20.31ms

  • After entering wifi key, wio name and submitting (with android app)
    [I 160430 12:36:01 handlers:86] get current user, id: 26, email: <>
    [I 160430 12:36:01 web:1946] 200 GET /v1/nodes/list (127.0.0.1) 6.26ms
    (multiple times, then timeout)

So the app is polling for changes on the server.
Problem is, that the Wio itself does not connect to the server, although wifi connection is established (confirmed via fritzbox log)

The led is blinking twice first, while connecting to wifi. The it starts blinking shortly once while trying to connect to server and stays is this state, even after the timeout.

Any other idea? :slight_smile:

Most importantly ther is no access to the apache server from the Wio itself, only from the android phone, I use.

[I 160430 12:33:39 server:535] SQLite version: 3.8.7.1
[I 160430 12:35:23 handlers:86] get current user, id: 26, email: <<censored>>
[I 160430 12:35:23 web:1946] 200 POST /v1/nodes/create?name=node000&board=Wio+Link+v1.0 (127.0.0.1) 20.31ms
[I 160430 12:36:01 handlers:86] get current user, id: 26, email: <<censored>>
[I 160430 12:36:01 web:1946] 200 GET /v1/nodes/list (127.0.0.1) 6.26ms
...and so on

Do you have the Chrome Application “Postman” or another REST test environment installed? Then we can test the connection manually (you can also use CURL, but I prefer Postman):

POST http://[your IP]:8080/v1/user/login?email=[your user]&password=[your password]

You should get an access token back.

GET http://[your IP]:8080/v1/nodes/list?access_token=[your access token]

Do you get a reponse for these two requests?
I intentionally bypassed the SSL part here by using http and port 8080 to test whether your problem is the certificate.

Hi,

I get the correct responses (I assume):

POST (http) rasp.fritz.box:8080/v1/user/login?email=<>&password=<>

{
  "token": "DcZCSVZYYxef6YWaQ9jMTIuw7pbOi8I0B4W-tEPI6Ro",
  "user_id": 26
}

GET (http) rasp.fritz.box:8080/v1/nodes/lis … 4W-tEPI6Ro

{
  "nodes": [
    {
      "name": "node000",
      "node_key": "3d2b6c044bd93e9f4db6f4a9e59ccb51",
      "node_sn": "dc1b971edd77011a6bf64cf88d205259",
      "dataxserver": null,
      "board": "Wio Link v1.0",
      "online": false
    }
  ]
}

Both requests also work via SSL

Thanks a lot for your support!

Seems you node is really not connected to the server (“online” : false).
Please try to delete the node:

POST http://[your IP]:8080/v1/nodes/delete?access_token=[you access toke]&node_sn=[the serial number of the node, see last response]

In the App logout your user. Change the custom IP address to the none SSL type (“http://[your IP]:8080”) and login again.
Try to register the node again.

That works.

So my taks will be to solve the SSL issue.

Hello uwe.fetzer, under Configure SSL when you say "Make sure, that you enter your (local) domain name at “Common name (FQDN), for example “*.se38.local” " where do you get your (local) domain name? Do you need a real FQDN? My server on a BBB is just local and only has an IP address with a local name. Everything I did will be at home and behind a firewall so I dont understand this step. Also you do not mention Steps 2.4 to 2.6.

I have a problem with 2.4 The command “supervisor” is to run the server at startup with the config file esp8266_server.conf. This file refers to " directory=/root/esp8266_iot_node/"
& “command=python /root/esp8266_iot_node/server.py”. In the whole process up to this stage this directory was never created. Using ubuntu command find / -name “esp8266*” -type d, the only files containing “esp8266*”. These are:
/opt/xtensa-lx106-elf/bin/Wio_Link/esp8266_arduino
/opt/xtensa-lx106-elf/bin/Wio_Link/esp8266_sdk
/usr/local/bin/Wio_Link/esp8266_arduino
/usr/local/bin/Wio_Link/esp8266_sdk

There is no directory at /root/esp8266_iot_node/. What is the correct directory? The command
“sudo supervisorctl start esp8266” fails.

Did you include the step, “2.6 Block 8080 port”? I can not get the command “supervisorctl restart esp8266” to work.
Thanks
Philip

Hello Philip,

some development environments check the requested URL against the FQDN in the certificate. In this case you will get an error message, if you just call the server via IP address. Just enter a domain name of your choice into the /etc/hosts (or \Windows\System32\drivers\etc\hosts on a Windows machine) of your client machine where you want to call the server.

Because you don’t need these steps if you follow my solution. The server starts automatically because of the last step (the entry in file /etc/rc.local)

Hope this helps
Uwe

Hello Uwe, thanks for you help. I was able to progress one extra step and I think I am nearly there! Local server is working and was able to connect wiolink computer to it. I was able to assemble hardware on the WioLink ports and accessed the APIs. Only problem was it did not Update and deliver the firmware to the WioLink computer but gave me an error message on both the server and the Android app.
On the server:
I 160502 12:24:47 handlers:555] get current node, id: 100, name: Wio05
rm -f *.elf *.hex *.d *.o *.a *.dump *.S
[E 160502 12:24:48 handlers:1332] /opt/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++: 1: /opt/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++: Syntax error: Unterminated quoted string

[I 160502 12:24:48 handlers:1459] +++send ota state to app:(‘error’, ‘/opt/xtens a-lx106-elf/bin/xtensa-lx106-elf-g++: 1: /opt/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++: Syntax error: Unterminated quoted string\n’)

I also got another previous error that related to “xtensa-lx106-elf/bin/xtensa-lx106-elf-g++”:

  1. in executing python ./build_firmware.py I get the error message:
    /opt/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++: 1: /opt/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++: Syntax error: Unterminated quoted string
    make: *** [Main.cpp.o] Error 2
    /opt/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++: 1: /opt/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++: Syntax error: Unterminated quoted string"

Did you come across this problem? How are you using your system? Are you using the “International” server for creating APIs and serving them locally? Thanks again
Android App4.JPG

Hi Philip,
sorry for beeing late, was on a business trip the last days.
And to answer your question: no, I haven’t got these error messages yet.

Maybe you should test, whether the server, the grove drivers or the Android App got updates in the meantime.
Also check, whether you’ve selected the correct file:

sudo wget http://arduino.esp8266.com/linuxarm-xtensa-lx106-elf-g46f160f.tar.gz

It has to be the ARM file for the Raspi.

Hello uwe, thanks very much for your help. Your advice was spot on. Although I am using a BBG it is also ARM based and the file you quoted was the one I needed. After re-compiling and connecting everything works locally. That is fantastic and your help was the key. Interestingly the support from the official WioLink release seems to be incorrect, confusing and complex. It needs to be re-written. What is interesting is that there is a lack of response from the original author of “Server Deployment Guide” github.com/Seeed-Studio/Wio_Lin … ment-Guide. I initially posted these issues on a separate post little response. This is disappointing. You departed from this procedure and I am interesting how you discovering the correct process and the correct files. Thanks again and now I can move on

Regards
Philip

Instructions updated due to a compile error (see last chapter). Maybe the Wio/Grove team have a look at this issue…

Thanks uwe.fetzer,
Is this method compatible with Raspberry Pi 2 ?
What is the lean_server.py files ?

It also should work on the Raspi2 because it’s also an ARM processor. Just try it out.
(and forget about the lean_server.py, you don’t need it with this solution)