tutorial on raspberry pi and iot toolslrahman/iot/files/raspberrypi_2.pdftutorial on raspberry pi...

11
RAHMAN, L.F. ([email protected]) 12/4/15 TUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things (2IMN15) 2015-2016, University of Technology Eindhoven By Leila F. Rahman ([email protected]) In this tutorial, we describe how to use the provided Raspberry Pi and some IoT tools for the Internet of Things (21MN15) practical. The Raspberry Pi has been configured and installed with the following tools: - txThings (CoAP implementation in Python) - Wakaama (LWM2M implementation in C) - Leshan (LWM2M implementation in Java) - Python 2.7 - Twisted 15.1.0 - Open Java JDK/JRE - Raspberry Pi Sense Hat Python Module - SSH - VNC For the practical, you can choose to use any of the development tools we provided (txThings, Wakaama or Leshan). You can also choose to use other frameworks or libraries, for example CoAP mplementations in various languages that you can choose from https://en.wikipedia.org/wiki/Constrained_Application_Protocol . However, we will support txThings, Wakaama and Leshan. The Raspberry Pi has been set with the following credentials: - User name: pi - Password: tue321 There are two ways to access the Raspberry Pi: 1. Directly from the device by connecting the device to a monitor with an HDMI cable and to a keyboard 2. Through SSH or VNC from a PC/Laptop (if monitor or HDMI cable or keyboard not available) In this tutorial, we will provide some guides for the following: 1. Installing necessary tools on PC 2. Using SSH from PC to access the Raspberry Pi 3. About txThings 4. Run CoAP Server on Raspberry Pi using txThings 5. Run CoAP Client from PC using txThings 6. Run Copper from Firefox 7. Compile and Run Wakaama on Raspberry Pi 8. Compile and Run Leshan on PC

Upload: others

Post on 15-Mar-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 1 of 11

Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things (2IMN15) 2015-2016, University of Technology Eindhoven By Leila F. Rahman ([email protected])

In this tutorial, we describe how to use the provided Raspberry Pi and some IoT tools for the Internet of

Things (21MN15) practical.

The Raspberry Pi has been configured and installed with the following tools:

- txThings (CoAP implementation in Python)

- Wakaama (LWM2M implementation in C)

- Leshan (LWM2M implementation in Java)

- Python 2.7

- Twisted 15.1.0

- Open Java JDK/JRE

- Raspberry Pi Sense Hat Python Module

- SSH

- VNC

For the practical, you can choose to use any of the development tools we provided (txThings, Wakaama

or Leshan). You can also choose to use other frameworks or libraries, for example CoAP mplementations

in various languages that you can choose from https://en.wikipedia.org/wiki/Constrained_Application_Protocol .

However, we will support txThings, Wakaama and Leshan.

The Raspberry Pi has been set with the following credentials:

- User name: pi

- Password: tue321

There are two ways to access the Raspberry Pi:

1. Directly from the device by connecting the device to a monitor with an HDMI cable and to a

keyboard

2. Through SSH or VNC from a PC/Laptop (if monitor or HDMI cable or keyboard not available)

In this tutorial, we will provide some guides for the following:

1. Installing necessary tools on PC

2. Using SSH from PC to access the Raspberry Pi

3. About txThings

4. Run CoAP Server on Raspberry Pi using txThings

5. Run CoAP Client from PC using txThings

6. Run Copper from Firefox

7. Compile and Run Wakaama on Raspberry Pi

8. Compile and Run Leshan on PC

Page 2: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 2 of 11

1 NECESSARY TOOLS ON PC

1. Install TightVnc Viewer – optional

2. Install Sublime Text – optional

3. If using Windows, install Cygwin (with the necessary packages including git, wget, ssh, openssh)

https://cygwin.com/index.html

http://www.davidbaumgold.com/tutorials/set-up-python-windows/

4. Install txThings and all the required dependencies (using git on Cygwin and pip)

git clone git://github.com/siskin/txThings.git

5. Install Copper on Firefox as a GUI client – optional

https://addons.mozilla.org/en-US/firefox/addon/copper-270430/

6. Install Wireshark – optional

7. Install Nmap for Windows

http://nmap.en.lo4d.com/

8. Install Leshan Server from Eclipse – optional

http://www.eclipse.org/leshan/

2 SSH TO RASPBERRY PI

1. Connect Raspberry Pi to the local network using UTP cable

2. Run Nmap on PC, search for the Raspberry Pi’s IP address by performing quick search on the IP

domain of the local network (e.g. Target: 192.168.0.*, Profile: Quick Scan)

3. Using Cygwin, connect to the Raspberry Pi with SSH and the following command:

a. ssh pi@ip_address

b. Password: tue321

4. Replace file /etc/network/interfaces with file interfaces.home with the following command:

cp interfaces.home /etc/network/interfaces

5. Replace file /etc/wpa_supplicant/wpa_supplicant.conf with file wpa-supplicant.home with

the following command:

sudo cp wpa_supplicant.home /etc/wpa_supplicant/wpa_supplicant.conf

6. Set the WiFi SSID and PASSWORD on /etc/wpa_supplicant/wpa_supplicant.conf to be able to

connect to the WiFi network

a. sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

b. replace the “SSID” and “PASSWORD” with the local WiFi credentials

Page 3: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 3 of 11

c. save the file and restart the Raspberry Pi with the following command:

sudo shutdown –r now

d. Raspberry Pi will be connected automatically to the local WiFi the next time it starts

Page 4: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 4 of 11

3 ABOUT TXTHINGS

txThings - CoAP library for Twisted framework

txThings is a Python implementation of Constrained Application Protocol (CoAP):

http://tools.ietf.org/html/rfc7252

txThings is based on Twisted - asynchronous I/O framework and networking engine written in Python.

http://twistedmatrix.com/

txThings uses MIT License (like Twisted itself).

http://opensource.org/licenses/mit-license.php

Copyright (c) 2012 Maciej Wasilak

http://sixpinetrees.blogspot.com/

txThings has the following features:

support for draft-ietf-core-coap-13 - including automatic piggyback/separate response handling. No

caching support.

support for draft-ietf-core-block-12 (no support for server initiative though - waiting for the

resolution)

limited support for RFC6690 (Core Link Format) - server only.

Other nice things:

txThings works nicely on RaspberryPi

txThings is compatible with Kivy - brilliant new Python GUI library

txThings is fully asynchronous (thanks to twisted framework)

txThings is posted on Github. The easiest way to get it is to clone the repository to your local machine using the command below:

git clone git://github.com/siskin/txThings.git

Library contains CoAP code (inside "iot" directory) and three examples:

server.py - CoAP server that starts on localhost, port 5683 and hosts several resources

client_GET.py - example client which performs GET request to localhost, port 5683

client_PUT.py - example client which performs PUT request to localhost, port 5683

Client_GET and client_PUT both use port 61616 - to use them simultaneously change port number in one of

the clients. Server will send blockwise responses for default settings. To use txThings you need Python 2.7

with Twisted installed (I suggest using the latest Twisted version, but older releases also work - tested with

11.1).

Page 5: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 5 of 11

4 RUN COAP SERVER ON RASPBERRY-PI WITH TXTHINGS’ EXAMPLE CODE

1. From the Raspberry’s console or using ssh to the Raspberry-Pi, go to the examples directory at :

libraries/txThings/examples

2. Run the CoAP server : python server.py

(See Figure 1)

Figure 1. Running the CoAP Server on Raspberry-Pi using SSH

5 RUN COAP CLIENT ON PC WITH TXTHINGS’ EXAMPLE CODE

1. If using Windows, open Cygwin

2. Go to the examples directory at : libraries/txThings/examples

3. Change the resource name and remote IP address in the source code of clientGET.py or

clientPUT.py (see Figure 2)

4. Run the CoAP clients (see Figure 3):

a. For GET operation: python clientGET.py

b. For PUT operation: python clientPUT.py

Page 6: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 6 of 11

Figure 2. Change the resource name and remote IP Address in the source code of clientGET.py

Page 7: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 7 of 11

Figure 3. Run clientGET.py on a Windows PC using Cygwin

6 RUN COPPER ON FIREFOX

The Copper (Cu) CoAP user-agent is an add-on for the Firefox Web browser. It allows browsing,

bookmarking, and direct interaction with CoAP resources. Simply enter a CoAP URI into the address bar

(See Figure 4, Figure 5 and Figure 6)

Page 8: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 8 of 11

Figure 4. Running the OBSERVE operation on the resource “time” using Copper

Page 9: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 9 of 11

Figure 5. Running the GET operation on the resource “counter” using Copper

Page 10: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 10 of 11

Figure 6. Running the PUT operation on the resource “block” using Copper

Page 11: Tutorial on raspberry pi and iot toolslrahman/iot/files/RaspberryPi_2.pdfTUTORIAL ON RASPBERRY PI AND IOT TOOLS Page 1 of 11 Tutorial on Raspberry Pi and IoT Tools v2 Internet of Things

RAHMAN, L.F. ([email protected]) 12/4/15

TUTORIAL ON RASPBERRY PI AND IOT TOOLS

Page 11 of 11

7 WAKAAMA ON RASPBERRY PI

For the practical, we don’t require the use of IPv6. Wakaama has been set by default to use IPv6. To

change the setting to IPv4, perform the following before compiling the code.

1. Wakaama distribution has been installed in ~\libraries\wakaama in the Raspberry Pi.

2. Open file wakaama\tests\utils\connection.c, and change in the function int

create_socket(const char * portStr), line 32 from AF_INET6 (IPv6) to AF_INET

(IPv4).

3. Compile and run Wakaama on Raspberry Pi following the steps on:

https://github.com/eclipse/wakaama

8 LESHAN ON PC

See http://www.win.tue.nl/~lrahman/iot/files/LeshanTutorial.pdf for more tutorial on Leshan.