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

Simplify IoT Development.

Moderators: violet, yexiaobo, seth.welday

User avatar
uwe.fetzer
Pre-kindergarten
Pre-kindergarten
Posts: 36
Joined: Sun Apr 17, 2016 6:06 am
Location: Neuss, Germany
Contact:

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

Post by uwe.fetzer » Fri Apr 22, 2016 6:09 pm

Raspberry Pi 3: WIO Link Server installation into the filesystem
see also https://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:

Code: Select all

sudo apt-get install vim
1. Configure SSL
See also https://www.digitalocean.com/community/ ... untu-14-04

Code: Select all

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”

Code: Select all

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:

Code: Select all

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

Code: Select all

<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

Code: Select all

sudo a2ensite default-ssl.conf
sudo service apache2 restart
2. Enable reverse-proxy for https and wss

Code: Select all

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_wstunnel

Code: Select all

sudo vim /etc/apache2/sites-available/default-ssl.conf 
Insert at the end (but before </VirtualHost>)

Code: Select all

           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

Again:

Code: Select all

sudo service apache2 restart

3. ESP8266 cross-compile toolchain

(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 http://arduino.esp8266.com/package_esp8 ... index.json )

Code: Select all

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

Code: Select all

:/opt/xtensa-lx106-elf/bin
Restart the Raspi or enter

Code: Select all

export PATH=$PATH:/opt/xtensa-lx106-elf/bin
4. Install the Python Server

Code: Select all

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
5. Install the Wio Server

Code: Select all

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
6. Start the Server

Code: Select all

python ./server.py
Compile the Grove Drivers

Code: Select all

python ./scan_drivers.py
Test

Code: Select all

python ./build_firmware.py
7. Autostart the Server

Code: Select all

sudo vim /etc/rc.local
at the end but before “exit 0”

Code: Select all

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

Update
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":

Code: Select all

cd /opt/Wio_Link
python server.py
Update the firmware via App and let the server autostart again as described in chapter 7.
Last edited by uwe.fetzer on Fri May 06, 2016 6:02 pm, edited 2 times in total.

bing.li2
Pre-kindergarten
Pre-kindergarten
Posts: 7
Joined: Tue Apr 19, 2016 12:53 pm

Re: [HowTo] Install the WIO Server on Raspberry Pi 3

Post by bing.li2 » Sun Apr 24, 2016 11:08 am

It is really coooooool !!!!

philip.mallon
Pre-kindergarten
Pre-kindergarten
Posts: 34
Joined: Fri Oct 31, 2014 12:32 pm
Contact:

Re: [HowTo] Install the WIO Server on Raspberry Pi 3

Post by philip.mallon » Thu Apr 28, 2016 3:23 pm

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: https://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.

User avatar
uwe.fetzer
Pre-kindergarten
Pre-kindergarten
Posts: 36
Joined: Sun Apr 17, 2016 6:06 am
Location: Neuss, Germany
Contact:

Re: [HowTo] Install the WIO Server on Raspberry Pi 3

Post by uwe.fetzer » Thu Apr 28, 2016 6:22 pm

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 ...

teng.wang
Pre-kindergarten
Pre-kindergarten
Posts: 37
Joined: Fri Apr 08, 2016 10:50 am

Re: [HowTo] Install the WIO Server on Raspberry Pi 3

Post by teng.wang » Fri Apr 29, 2016 9:59 am

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

kai.timofejew
Pre-kindergarten
Pre-kindergarten
Posts: 5
Joined: Fri Apr 15, 2016 11:01 pm

Re: [HowTo] Install the WIO Server on Raspberry Pi 3

Post by kai.timofejew » Sat Apr 30, 2016 5:57 pm

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

User avatar
uwe.fetzer
Pre-kindergarten
Pre-kindergarten
Posts: 36
Joined: Sun Apr 17, 2016 6:06 am
Location: Neuss, Germany
Contact:

Re: [HowTo] Install the WIO Server on Raspberry Pi 3

Post by uwe.fetzer » Sat Apr 30, 2016 6:24 pm

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

Code: Select all

cd /opt/Wio_Link
python server.py
Ther server should start now and you should see the communication, for example

Code: Select all

[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?

kai.timofejew
Pre-kindergarten
Pre-kindergarten
Posts: 5
Joined: Fri Apr 15, 2016 11:01 pm

Re: [HowTo] Install the WIO Server on Raspberry Pi 3

Post by kai.timofejew » Sat Apr 30, 2016 6:43 pm

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: <<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

- After entering wifi key, wio name and submitting (with android app)
[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
(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? :)

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

Code: Select all

[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
Last edited by kai.timofejew on Sat Apr 30, 2016 7:00 pm, edited 1 time in total.

User avatar
uwe.fetzer
Pre-kindergarten
Pre-kindergarten
Posts: 36
Joined: Sun Apr 17, 2016 6:06 am
Location: Neuss, Germany
Contact:

Re: [HowTo] Install the WIO Server on Raspberry Pi 3

Post by uwe.fetzer » Sat Apr 30, 2016 6:59 pm

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):

Code: Select all

POST http://[your IP]:8080/v1/user/login?email=[your user]&password=[your password]
You should get an access token back.

Code: Select all

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.

kai.timofejew
Pre-kindergarten
Pre-kindergarten
Posts: 5
Joined: Fri Apr 15, 2016 11:01 pm

Re: [HowTo] Install the WIO Server on Raspberry Pi 3

Post by kai.timofejew » Sat Apr 30, 2016 7:08 pm

Hi,

I get the correct responses (I assume):

POST (http) http://rasp.fritz.box:8080/v1/user/logi ... <<censored>>

Code: Select all

{
  "token": "DcZCSVZYYxef6YWaQ9jMTIuw7pbOi8I0B4W-tEPI6Ro",
  "user_id": 26
}
GET (http) http://rasp.fritz.box:8080/v1/nodes/lis ... 4W-tEPI6Ro

Code: Select all

{
  "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!

Post Reply