Tuesday, February 28, 2017

The Next Web Applications — From an IoT Point of View

The Internet is a scalable global network of computers that interoperates across heterogeneous hardware and software. On top of the Internet, the Web is an outstanding example of how a set of relatively simple and open standards can be used to build very complex systems while preserving efficiency and scalability. The Web and its underlying open protocols have become a part of our everyday life — something we access at home or on the move, through our laptops, phones, tablet, TV, or wearable devices. It has changed the way we communicate and has been a key factor in the way the Internet has transformed the global economy and societies around the world.

Meanwhile, the Internet of Things will allow physical objects to transmit data about themselves and their surroundings, bringing more information about the real world online and help users to better interact with their surroundings. Flowers, for example, can send you an email or a SnapChat photo of your flower when they need watering. Doctors can implant sensors in your body that give you real-time updates about your health updating frequently to a secure online database of your personal data. Even more, IoT data will go beyond the scope of each own service provider to go online and share with other applications and users.

In the next Web, applications will interact with smart objects through communication networks using open Web standards. These applications are the natural evolution of Web application when today’s Internet is transforming to the Internet of everything to include smart objects in the loop. There can be an application to get access to your Google calendar with the note of cleaning your living room to have your mother visit in few hours. The application then asks your robot cleaner to automatically wake up and do cleaning. Robot cleaner notifies you (by sending an email or a SnapChat message) when it starts working or finishes the work. Another application can let you talk to your devices in the way you talk to your friend with the support of natural language processing engines; this is the new experience of making friendship with your devices. Yet another application can serve you in the airport to update the status of the flight, providing practical information in the airport, connecting to the boarding machine to update you for any delay of boarding time that you can spend more time doing shopping in duty free. Yet another application can synchronize your TV programs and football schedule and also your social network profile to remind you an upcoming match. These applications all require the interactions of existing Web services and new services from smart objects to create new user experience while assuring the seamless transition from developing traditional Web applications to this new type of the next Web applications.

Monday, April 6, 2015

Contiki OS: Using Powertrace and Energest power profile to estimate power consumption

To estimate the energy consumption. We can run on Cooja or with a real device

- Check the number of ticks per sencond for rtime (RTIMER_SECOND = 32768)
printf("Ticks per second: %u\n", RTIMER_SECOND);

- Include powertrace app in your project by adding it to your Makefile
APP += powertrace
(You also can use simpler version of powertrace at https://github.com/sonhan/contiki-sonhan/)
- Add to source file
#include "powertrace.h"
- Add to source file to print power profile every 10 seconds:
powertrace_start(CLOCK_SECOND * 10);

- Sample data
CPU         LPM            TX           RX
512803    14227588    153188    195436
531519    14535272    158359    203847
549549    14844701    163409    211794
560341    15161365    165821    216534
575755    15473409    169844    223419
599333    15777318    178173    231767
610307    16093852    180704    236651
625674    16406020    184722    243660
649197    16710040    193402    252940
660144    17026626    195811    258453
670942    17343372    198221    263249

- Energy consumption (Power - mW):

Check datasheet for current and voltage, e.g., CPU = (531519 - 512803) * 0.33 * 3 / 32768 / 10

- Duty cycle (%):


E.g., TX duty cycle = (158359 - 153188) / (531519 - 512803 + 14535272 - 14227588)

- Sample output:
- Sample data and calculation:
https://github.com/sonhan/contiki/tree/master/apps/powertrace-sonhan/sample-data

Friday, February 13, 2015

Contiki and Z1

platform/z1/contiki-conf.h: change UIP_CONF_BUFFER_SIZE to 240 (from 140)

make z1-reset
make login

...to be continued

Quick Start: gnuplot - multiline graph

- Download and install gnuplot: http://www.gnuplot.info
- Creat a file data.txt:

Time    TX    RX    Total
1    0.00%    0.95%    0.95%
2    0.00%    1.03%    1.03%
3    0.09%    0.83%    0.92%
4    0.09%    1.09%    1.17%
5    0.00%    0.69%    0.69%
6    0.09%    1.07%    1.16%
7    0.00%    1.02%    1.02%
8    0.09%    1.15%    1.25%
9    0.09%    0.85%    0.94%
10    0.00%    0.92%    0.92%
11    0.18%    0.98%    1.16%
12    0.18%    1.19%    1.37%
13    0.18%    1.36%    1.54%
14    0.23%    1.30%    1.52%
15    0.00%    0.89%    0.89%
16    0.09%    1.17%    1.26%
17    0.09%    1.26%    1.35%
18    0.00%    1.13%    1.13%
19    0.18%    1.28%    1.46%
20    0.09%    0.84%    0.93%

- Run in gnuplot>

set xlabel 'Time (s)'
set ylabel 'Duty Cycle (%)'
set yrange [0:2]
set xrange [1:20]
set key autotitle columnheader
plot "data.txt" u 1:2 w linespoints lt -1 pt 5 dt 5, '' u 1:3 w linespoints lt -1 pt 4 dt 2, '' u 1:4 w linespoints lt -1 pt 3

- Output

Tuesday, August 19, 2014

Quickstart: Raspbian (Raspberry Pi) Common Errors

-  FAT-fs (mmcblk0p1): Volume was not properly unmounted

Reason: (http://lkml.org/lkml/2013/5/6/342) dosfstools should be at least v3.0.14, the current version is: 3.0.13-1
How to: (http://www.tuxlog.de/raspberrypi/2014/raspberry-pi-volume-not-properly-unmounted/)

sudo umount /boot
sudo git clone http://daniel-baumann.ch/git/software/dosfstools.git
sudo cd dosfstools
sudo make
sudo ./fsck.fat -V /dev/mmcblk0p1

0x25: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
1) Remove dirty bit
2) No action
? 1

sudo ./fsck.fat -a /dev/mmcblk0p1
sudo mount /boot

(Updating...)

Monday, June 2, 2014

Border Router with Raspberry Pi for LLN with TelosBs

This tutorial aims to create a IPv6 Low-power and Lossy Network (LLN) of TelosB motes with a Rapsberry Pi (RPi) as a border router (LBR) to connect to other IPv6 networks. RPi is configured for routing traffic from the LLN to other IPv6 networks by creating a TUN network interface. An alternative to setup a LLN is to configure a bridge (TAP) as in Cetic-6LBR (https://github.com/cetic/6lbr/)

We are going to have two IPv6 networks associated to two network interfaces of the LBR RPi as shown in Fig.1.

Fig.1: Deployment


LBR
- eth0: bbbb::1/64 (Physical Ethernet interface to normal IPv6 network)
- tun0: aaaa::1/64 (TUN interface to LLN)

IPv6 Network:
- bbbb::2

LLN:
- aaaa::212:7400:13cb:44 (slip-radio)
- aaaa::212:7400:13cb:101a
- aaaa::212:7400:13ca:f3ac

1. LLN Network (see here)

- Flash radio-slip mote (contiki-2.7/examples/ipv6/slip-radio) to use as an IEEE 802.15.4 interface
- Flash other TelosB for LLN nodes (e.g., contiki-2.7/examples/ipv6/udp-server)

2. IPv6 Network
- Configure a machine with bbbb::/64 address (example with a Linux)
# sudo vi /etc/network/interfaces
auto eth0
iface eth0 inet6 static
address bbbb::2
netmask 64
gateway bbbb::100 (border router address)

(you may need to deactivate other network interfaces to check if it works properly)

3. RPi Border Router
Prepare RPi OS
- Download Raspbian

- Create a boot disk using SD card (>4G) using Win32 DiskImager
(Check here for Raspbian essentials)

- Plug radio-slip mote to RPi, recognized as /dev/ttyUSB0

- Enable IPv6 module?

# sudo modprobe ipv6
or to automatically enable it at boot, add ipv6 on a line at the end of /etc/modules.

- Enable IPv6 forwarding
# sudo sysctl -w net.ipv6.conf.all.forwarding=1

or edit /etc/sysctl.conf uncomment the line: net.ipv6.conf.all.forwarding=1

- Configure IPv6 address for eth0
# sudo vi /etc/network/interfaces
auto eth0
iface eth0 inet6 static
address bbbb::1
netmask 64

- Download contiki-2.7 source
- Go to examples/ipv6/native-border-router
- Fix source and build 
# vi border-router.c, line 161: remove ; (contiki 2.7 bug)
# vi slip-config.c, line 76: change -1 to 255 (RPi kernel??)
# make

- Run border router
# sudo modprobe ipv6 (optional)
# sudo sysctl -w net.ipv6.conf.all.forwarding=1 (optional)
# sudo ./border-router.native -L -v6 aaaa::1/64 (debug, ttyUSB0, 115200)

Autostart the border-router.native by adding it to /etc/rc.local (optional)
path_to_border-router.native aaaa::1/64

ex: /home/pi/contiki-2.7/examples/ipv6/native-border-router/border-router.native aaaa::1/64 &

4. Test

From IPv6 network computer ping to LLN
Ping: ping6 aaaa::212:7400:13cb:101a
Web browser: aaaa::212:7400:13cb:44

Thursday, May 29, 2014

Quickstart: Raspbian (Raspberry Pi) Essentials

Prepare booting SD card
SD card > 4G, http://www.raspberrypi.org/documentation/installation/installing-images/README.md

Example with Raspbian
- Download: http://downloads.raspberrypi.org/raspbian_latest
- Download the Win32DiskImager utility from Sourceforge Project
- Make booting SD card from the downloaded image using Win32DiskImager

USB Serial Console (no need a monitor and keyboard)
https://learn.adafruit.com/adafruits-raspberry-pi-lesson-5-using-a-console-cable/overview


VNC Server
http://elinux.org/RPi_VNC_Server

Youtube player
https://pypi.python.org/pypi/whitey

Enable IPv6
Easy. sudo modprobe ipv6 will enable it immediately. If you want it to automatically be enabled at boot, just add ipv6 on a line by itself at the end of /etc/modules.  

Tips
- SD card will appears in Windows only with its boot partition, which is few hundred kb
- If Ethernet doesn't work, check power source using official cable

Thursday, April 17, 2014

Light sensing with TelosB

A small application to demonstrate IP networking in smart objects: Light sensing with TelosB motes + Contiki OS + uIP stacks.

Equipment needed
- 02 TelosB motes
- 01 gateway machine: Java supported, USB port

Setup
- 01 mote is connected to the gateway as a sink node to receive data from the other mote. It is an UDP server to print the received data to serial port
- 01 motes frequently collect light intensity and send it to the sink node if the intensity changes dramatically (higher than a predefined THRESHOLD = 2). It is an UDP client to send data
- Gateway: Using serialdump* tool to get data from the sink node's serial port and a Java client running to capture these data.

Source code
https://github.com/sonhan/ipsensorcollect

Demo

The bottom panel gets darker if  light intensity reduces

Friday, March 21, 2014

Contiki OS 2.7 Cooja Serial Device with serial2pty

Create a virtual serial device for Cooja motes under /dev/pts/[id]

1. Download
https://github.com/cmorty/cooja-serial2pty
2. Update code with new Cooja class names (if not updated) in Serial2Pty.java

- Change package org.contikios.cooja to se.sics.cooja
import se.sics.cooja.*;
import se.sics.cooja.interfaces.SerialPort;
- Change class Cooja to GUI

A modified code can be found here: https://github.com/sonhan/cooja-serial2pty

3. Build
copy to /contiki/cooja/apps/serial2pty
ant jar
cooja > Settings -> Cooja Extensions... > Select the serial2pty app

4. Test
- Restart Cooja if needed
- Right click on the mote > Mote tools for Test Node > Serial 2 Pty > it shows the serial device (e.g., /dev/pts/10
- Open a Terminal:

#cd contiki
#sudo make login TARGET=sky MOTES=/dev/pts/10 (for a simulated Sky mote)

Thursday, March 6, 2014

Contiki OS: RPL Network Setup 2

One mote can be used as a wireless interface (IEEE 802.15.4), host machine as Border Router to  bridge the wireless IPv6 network (e.g., LLN) to outside network, and the Internet.

InstantContiki 2.7 or any machine with Contiki-2.7 and TI MSP430 toolchain (See here)

1. slip-radio (mote 1 as an IEEE 802.15.4 interface)
#cd contiki-2.7/examples/ipv6/slip-radio
#make TARGET=sky
#sudo make TARGET=sky slip-radio.upload

2. UDP servers or any IPv6 service (motes 2..n)
#cd contiki-2.7/examples/ipv6/rpl-udp
#make TARGET=sky
#sudo make TARGET=sky udp-server.upload

3. Host machine (Linux)
 #cd contiki-2.7/examples/ipv6/native-border-router
#make [TARGET=native]
#sudo ./border-router.native -L -v6 aaaa::1/64
*default: -s ttyUSB0 (serial device) -B 115200 (baud rate) -t tun0 (name of interface)

Cooja:  sudo ./border-router.native -a 127.0.0.1 -v6 aaaa::1/64
(enable Serial  Socket Server in the Cooja node used as the wireless interface)

[Contiki 2.7 Release Error] border-router.c:161:28: error: expected ‘)’ before ‘;’ token. 
Just delete the ';'

4. Test
ping6 aaaa::212:7400:13cb:44 (mote 1, wireless interface)
ping6 aaaa::212:7400:13ca:fee4 (mote 2)
ping6 aaaa::212:7400:13cb:34fa (mote 3)

Firefox: http://[aaaa::212:7400:13cb:44]

Thursday, February 20, 2014

Contiki OS: Handy Commands and Tools (TelosB)

Linux
#make TARGET=sky savetarget (save target)
#make [TARGET=sky] motelist (list of attached motes)
#sudo [TARGET=sky] make login (mote console)
#make [TARGET=sky] MOTES=/dev/ttyUSB1 (target at the motes /dev/ttyUSB1)
#sudo make [MOTES=/dev/ttyUSB1] name_of_program.upload (upload to [ttyUSB1]) 


Windows
cd tools\sky
motelist-windows.exe (list of attached motes)
serialdump-windows.exe -b115200 /dev/com5 (mote console of COM5 mote, baud rate 115200)

TelosB driver:  FTDI
http://www.ftdichip.com/FTDrivers.htm

Monday, February 17, 2014

Contiki OS: Run Contiki Collect View tool on Windows, Linux

Collect View is a Contiki tool to collect and visualize data from a mote (including energy consumption)

Requirements
- 01 Host machine (Windows or Linux TI MSP430 toolchain)
- 02 TelosB motes

Motes setup
- Use InstantContiki or Linux with TI MSP430 toolchain (see here)
- Connect 02 motes
- Build and upload udp-sink (sink node) and udp-sender (send node
cd examples/ipv6/rpl-collect
make PERIOD=10 (sending every 10sec) if this doesn't work change in the source file collect-common.c #define PERIOD 10

make TARGET=sky MOTES=/dev/ttyUSB0 udp-sink.upload
make TARGET=sky MOTES=/dev/ttyUSB1 udp-sender.upload

Windows environment setup
- Download Contiki source (contiki-2.7)
- Download ANT and extract to a folder (E:\dev\apache-ant-1.9.3)
- Add System Environment variable ANT_HOME=E:\dev\apache-ant-1.9.3
- Add %ANT_HOME%\bin to your PATH

build.xml fix (for Windows)
- Remove the collect-view-shell.ihex part (it is used to compile collect example and copy to the dist folder)
<target name="collect-view-shell.ihex"
<target name="dist" depends="jar,collect-view-shell.ihex">

Go and rock
- Connect sink node to the host machin
- Run Terminal or cmd (Windows with administrator)

cd contiki-2.7\tools\collect-view
ant (building)
cd dist
java -jar collect-view.jar /dev/com6 (Windows, COM6 is the device port)
sudo java -jar collect-view.jar /dev/ttyUSB0 (Linux, ttyUSB0 is the device port)

Click Start Collect

Tuesday, February 11, 2014

Contiki OS: TelosB Toolchain TI MSP430 Installation Ubuntu + Cygwin (Windows)

Official Website

http://sourceforge.net/apps/mediawiki/mspgcc/index.php?title=MSPGCC_Wiki 

Ubuntu

Install libncurses
$ sudo apt-get install libncurses5-dev

Install msp430 toolchain
$ sudo apt-get install msp430-libc mspdebug msp430mcu binutils-msp430 gcc-msp430 gdb-msp430

[ia32-libs]

Cygwin

Make sure rpm package is installed (Run setup again, under util if rpm cannot be found)

Sunday, February 9, 2014

Contiki OS: RPL Network Setup 1

One mote can be used as a Border Router to bridge the wireless IPv6 network (e.g., LLN) to a PC via serial link. By which, the IPv6 network traffic can reach outside network, and the Internet.

InstantContiki 2.7 or any machine with Contiki-2.7 and TI MSP430 toolchain (See here)

1. Border router (mote 1)
#cd contiki-2.7/examples/ipv6/rpl-border-router
#make TARGET=sky
#sudo make TARGET=sky border-router.upload

2. UDP servers (motes 2..n) or any IPv6 service
#cd contiki-2.7/examples/ipv6/rpl-udp
#make TARGET=sky
#sudo make TARGET=sky udp-server.upload

3. Host machine 

- Linux using tunslip6 (with mote 1 connected as ttyUSB0)

#cd contiki-2.7/tools
#make tunslip6
#sudo ./tunslip6 -s /dev/ttyUSB0 aaaa::1/64

Cooja: sudo ./tunslip6 -a 127.0.0.1 aaaa::1/64
(enable Serial  Socket Server in the Cooja node used as the wireless interface)

- Windows using wpcapslip6 (with mote 1 connected as COM5)
Run cmd (Admin)
ifconfig /all --> find a working network interface (e.g.,Virtual Box Network Interface), MAC address: 00-50-56-C0-00-01
cd tools\stm32w\wpcapslip6
wpcapslip6 -s /dev/com5 -b aaaa:: -a aaaa::1/64 00-50-56-C0-00-01 (COM5 is where the mote is connected, check in Device Manager)

4. Test
ping6 aaaa::212:7400:13cb:44 (mote 1, border router)
ping6 aaaa::212:7400:13ca:fee4 (mote 2)
ping6 aaaa::212:7400:13cb:34fa (mote 3)


Firefox: http://[aaaa::212:7400:13cb:44]

Monday, March 25, 2013

Quick Start: LaTeX Bibliography - BibTeX

1. LaTex Template: download and extract to latex_template
ex: IEEE template (http://www.ieee.org/documents/windows_latex_template.zip)
2. Bibliography style: download and extract to latex_template folder
ex: IEEE style (http://www.ieee.org/documents/IEEEtranBST.zip)
3. Create a BibTeX file example.bib by several ways:
- Many articles have their own BibTeX code to download
- Use a text editor, ex: TexMaker (http://www.xm1math.net/texmaker/)
- Use a References Management software, ex: JabRef (http://jabref.sourceforge.net/)
4. Cite references
- A reference consists of a Bibtexkey (e.g., Han:2011) and other infos
- Cite in a document by \cite{Han:2011}

Friday, December 21, 2012

Use a Linux Machine as Web Proxy


Prerequisites:
- Linux machine: Ubuntu with SSH connection, says, 98.138.253.109, port 22, user bossie
- Windows machine: PuTTy, Firefox browser

PuTTy:
- Put in SSH info (Hostname: 98.138.253.109, Port: 22, Connection type: SSH)
- Left panel: Connection > SSH > Tunnels and add server info with a port number, says 8888 then click Add button

 - Open connection, log in

Firefox:
- Options > Advanced > Network > Settings.
- Choose Manual proxy configuration, enter localhost for the SOCKS Host, and 8888 for the Port.


VoilĂ  your proxy. Browse Web through 98.138.253.109

Thursday, December 20, 2012

Quick Start: Graph with Matlab

Prepare data in file ttidata.m

1 157 1851 (separated by TAB)
2 203 1864
3 250 1866
4 281 1869
5 313 2187
6 344 2713
7 359 2716
8 375 2942
9 406 3039
10 453 3301

Draw (x, y) and (x, z) graphs on the same canvas

load ttidata.m
y = ttidata(:,2);
z = ttidata(:,3);
plot([1:length(y)],y,'g-x')
hold on
plot([1:length(z)],z,'g-x')

Quick Start: LaTeX

Environment Preparation
1. LaTex package: download and install
- MiKTex: http://miktex.org/
2. LaTex editor: download and install
- TexMaker: http://www.xm1math.net/texmaker/
3. Template: download and extract
- IEEEtran: http://www.ieee.org/documents/windows_latex_template.zip

Hello World
1. Open bare_jrnl.tex in the IEEEtran template with TexMaker and edit it as you wish.
2. Build the document by F6 (PDFLaTeX) and view F7 (View PDF)