Enable Arduino Yun bridge on Linkit 7688 Duo

If you already have code written for your Arduino yun which uses the Yun bridge and you want to run it on your Linkit 7688 Duo you can also enable this library.

Use following commands to enable Bridge library on LinkIt Smart 7688 Duo:

uci set yunbridge.config.disabled='0'
uci commit
reboot

In your sketch you can now add Bridge.begin(); in the setup which will trigger the run-bridge shell script which invokes python bridge.py from /usr/lib/python2.7/bridge.

Linkit 7688 Duo DHT22

Both the Linkit 7688 and DHT22 are low cost components and can perfectly be used as a IOT temperature and humidity device. Using the openwrt part of the linkit to upload all the data to your server.

DHT22 specs:

  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 0-100% humidity readings with 2-5% accuracy
  • Good for -40 to 125°C temperature readings ±0.5°C accuracy
  • Body size 15.1mm x 25mm x 7.7mm

The DHT22 has has four pins

  • VCC (3 to 5V power)
  • Data out
  • Not connected
  • Ground

You can ignore pin 3, its not used. Please use a pull-up resistor between VCC and the data pin (10k).

Below pictures shows the connection diagram.

Linkit 7688 Duo DHT22
Linkit 7688 Duo DHT22

Now we need to install the DHT library. You can find the latest libraries here: https://github.com/adafruit/DHT-sensor-library

Or download from my website: DHT-sensor-library-master

You can use the following sourcecode written by layada. If you download the libraries you can also get the code from the example menu.

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2 // what digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");

dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}

With the arduino ide 1.6.9 you will receive a compile error “magic key not defined”. You can download and use the hourly builds to solve this issue.

The serial output will look like this:

Humidity: 49.40 % Temperature: 25.00 *C 77.00 *F Heat index: 24.85 *C 76.72 *F
Humidity: 49.40 % Temperature: 25.00 *C 77.00 *F Heat index: 24.85 *C 76.72 *F
Humidity: 49.40 % Temperature: 25.00 *C 77.00 *F Heat index: 24.85 *C 76.72 *F
Humidity: 49.40 % Temperature: 24.90 *C 76.82 *F Heat index: 24.74 *C 76.52 *F
Humidity: 49.40 % Temperature: 25.00 *C 77.00 *F Heat index: 24.85 *C 76.72 *F

The fritzing parts you can download here:
LinkIt_Smart_7688_Duo_DHT22_diagrams

Linkit 7688 No Wifi after initial boot

After unpacking the Linkit Smart 7688 and power it up I did not get any Wifi network.

Normal behaviour: After the boot loader has initialized the boot up process begins, which takes about 30 seconds. Next, the Wi-Fi LED turns off; this means the system is ready to accept a Wi-Fi connection. The 7688 becomes an access point (AP) based on his mac address (LinkIt_Smart_7688_XXXXXX, where xxxx is the mac address)

Unfortunately I did not see any SSID broadcasted. To solve this please do a factory reset using the Wifi button (middle button).

Procedure:

  1. Boot up the board and wait for the Wi-Fi LED to go off.
  2. Press and hold the Wi-Fi button for at least 20 seconds and release.
  3. The Wi-Fi LED will blink fast for 1 second while performing a factory reset.

Now you can connect to the board.

Start nodejs script during bootup on your RPi

If you have written a nodejs script you want to be able to run this application as a daemon on your linux system. For this purpose you could use Forever. The purpose of Forever is to keep a child process (such as your node.js web server) running continuously and automatically restart it when it exits unexpectedly. In this article you can find how to install forever and launch a nodejs script in init.d.

Installation

sudo npm -g install forever

Command Line Usage
You can use forever to run scripts continuously (whether it is written in node.js or not).
Start:

forever start server.js
Output:
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: server.js

Stop:

forever stop server.js
Output:
info:    Forever stopped process:
    uid  command             script    forever pid   id logfile                 uptime
[0] MKqv /usr/local/bin/node server.js 19915   19920    /root/.forever/MKqv.log 0:0:1:14.969

Start script during boot
To start your script during boot on your raspbian you will need to create a script in /etc/init.d. In this example I will use a script called nodestart to which you can provide two arguments “start” and “stop”. The nodejs script is called “server.js”.

#!/bin/sh
#/etc/init.d/nodestart

export PATH=$PATH:/usr/local/bin
export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules

case "$1" in
  start)
  exec forever --sourceDir=/[directory to your script] -p /[log directory] server.js
  ;;
stop)
  exec forever stopall
  ;;
*)
  echo "Usage: /etc/init.d/nodeup {start|stop}"
  exit 1
  ;;
esac

exit 0

Your almost there! Make the script executable and install it:

chmod 755 /etc/init.d/nodestart
update-rc.d nodeup defaults

Now it will be automatically started during boot or you can try it via the CLI:

/etc/init.d/nodestart start

You can remove the script via:

update-rc.d -f nodestart remove

Install nodejs on RPi2

Unfortunately nodejs is no longer maintained via an installation of apt-get install on the raspberry PI. Please use below instructions for the installation.

Be sure that you first remove the old one:

sudo apt-get remove nodejs

Then check on the nodejs site the latest version: https://nodejs.org/dist/latest/
In my case it is: node-v6.0.0-linux-armv7l.tar.gz

For the RPi1 use should use armv6l.tar.gz

Now it’s time to download and install.

wget https://nodejs.org/dist/latest/node-v6.0.0-linux-armv7l.tar.gz
tar -xvf node-v6.0.0-linux-armv7l.tar.gz 
cd node-v6.0.0-linux-armv7l
sudo cp -R * /usr/local/

Your done! Now check that it is working by node -v

RC522 with Raspberry Pi 2

The RC522 is a cheap RFID module that can read and write Mifare’s tags and being sold at several web stores, like eBay and included with many “starter kits” nowadays. Simply search RFID-RC522 (MF-RC522). The card reader and the tags communicate using a 13.56MHz electromagnetic field. (ISO 14443A standart tags)

Wiring up:

Below table shows the connection between RC522 and RPi2:

RC522 pin RPi2 pin nr RPi2 pin name
SDA 24 GPIO8
SCK 23 GPIO11
MOSI 19 GPIO10
MISO 21 GPIO9
IRQ Remark: Not connected
GND GND GND
RST 22 GPIO25
3.3V 1 3V3

Please note that the RPi2 has a 40 pin header (RPi1 has 25).

Wiring RPi2 and RC522

RPi2 steps:

We need to enable all the python libraries and the SPI interface on the RPi2 to get it working.

To install the python environment:

sudo apt-get install python-dev

enable spi interface:
Edit the file /boot/config.txt and add the following two lines:

device_tree_param=spi=on
dtoverlay=spi-bcm2708

To check if the SPI interface is working, please reboot the RPi and run the following instructions:

$ dmesg | grep spi

The output will look like:

[ 10.886588] bcm2708_spi 3f204000.spi: master is unqueued, this is deprecated
[ 10.901487] bcm2708_spi 3f204000.spi: SPI Controller at 0x3f204000 (irq 80)

Now download and install the SPI python library:

git clone https://github.com/lthiery/SPI-Py.git
$ cd SPI-Py
$ sudo python setup.py install

Now download and run the RC522 lib:

$ git clone https://github.com/rasplay/MFRC522-python.git
$ cd MFRC522-python
$ python read.py

The output will look like:

Card detected
Card read UID: 98,40,242,197,125

Windows versus Linux for Netbeans

This article is an old story about two different camps, the Linux or the Windows side. To be honest I find that windows 7 suites my needs and is always easy to work with, where with Linux you need sometime some more configuration effort (time) to get things working.

Nevertheless, I started programming with Java EE 7 and Glassfish/Payara and have chosen Netbeans as IDE. The startup under windows took quite some while and after watching some youtube tutorials I thought that the startup speed could be faster. So I decided to install Ubuntu 14.04 LTS on the same machine as dual boot.

Version and conditions:
– Netbeans 8.1
– Windows 7 with all patches/SP (waited till the OS loaded everything)
– Ubuntu 14.04 LTS (waited till the OS loaded everything)
– All projects closed in Netbeans, only startup time was measured

Windows:
First startup: 49,48 s
Second startup: 9,76 s (first started and closed outlook and chrome)

Ubuntu:
First startup: 23,46 s
Second startup: 7,43 (first started and closed thunderbird and chrome)

It seems that Ubuntu will be my preferred development environment ;-). Also the responsiveness with Ubuntu is faster and the startup of Pyara server is faster as well.

Turn your Raspberry PI into a malicious network traffic scanner with wireshark

I needed to scan a network with wireshark to check for malicious traffic. I took my RPi turned into a router with a DHCP server and installed wireshark to check all the network traffic.

Step 1: Static IP address

See my previous article for the setup.

Step 2: Install and configure DHCP server

In this case I’ve chosen the ISC as DHCP server. To install:

sudo apt-get install isc-dhcp-server

For the configuration, please edit /etc/dhcp/dhcpd.conf and add the following:

subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.20 192.168.100.39;
option broadcast-address 192.168.100.255;
option routers 192.168.100.1; option domain-name-servers 8.8.8.8;
}

Now we need to tell the daemon some specifics, please edit /etc/default/isc-dhcp-server and uncomment the following:

DHCPD_CONF=/etc/dhcp/dhcpd.conf
DHCPD_PID=/var/run/dhcpd.pid
INTERFACES="eth0"

And add “eth0” to the interfaces list, this tells the daemon on which interface he needs to react on.

Before you run the DHCP server please stop the DHCP server on your rputer. Now you can start the daemon on your RPi with: sudo service isc-dhcp-server start

If you run into any problems please use systemctl status isc-dhcp-server.service to check the output.

You can use cat /var/lib/dhcp/dhcpd.leases to check out the leases.

Step 3: Turn your RPi into a router

Your RPi is now able to respond to DHCP requests, but now we need to be able to forward the traffic.

sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'

Please edit /etc/sysctl.conf and uncomment out the line that says net.ipv4.ip_forward = 1
Last step is to enable NATTING via IPtables:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Excellent, your RPi is now a router in your network and forwarding the traffic.

Step 4: Wireshark
I want to see all network traffic and for this purpose I installed wireshark. The RPi2 is fast enough to use the GUI of wireshark. For this purpose I installed tightvncserver and wireshark.

sudo apt-get install tightvncserver
sudo apt-get install wireshark

Now with a VNC client you can connect to your RPi and start wireshark in a terminal. You can use not (port 5901) as capture filter which does not capture the VNC traffic.

wireshark capture

How to setup a static IP address raspberry PI

You cannot get a static or fixed IP address working on you Raspberry PI with the current tutorials? Then you came to the right place!

The raspberry PI is an excellent device and I use it often as a server to host my projects. For most of my project I need a static IP address on my RPi. I thought that this would be an easy job just to change the /etc/network/interfaces (also according to a lot of tutorials).  Turns out that from the jessie image (kernel 4.x) you need to change the dhcpd.conf. Below I will explain in detail the steps and some more guidance on where to configure your static IP address.

Network

Before you add a static IP address on your RPi, please consider where you want to make the configuration. It makes a lot of sense to configure your DHCP server (in most home networks your ISP router) with the appropiate settings rather then on the RPi.  Based on the MAC address of your device the router is able to hand out a static IP address. Configuring this on your router makes administration easier due to the fact that you have 1 administration where all the data of the devices with a static IP address is stored.

Bonjour

Now that you have configured your router and your RPi has a static IP you can log on to the given IP address. But we people are better in remembering a name than numbers. So to make life more easier you can install avahi on your RPi.

Avahi is a linux implementation which enables programs/OS to publish and discover services and hosts running on a local network. For example, a user can plug their computer into a network and have Avahi automatically advertise the network services running on the machine which could enable access to files and printers.

The protocol behind avahi is known as Multicast Domain Name Service (mDNS) and can also be used as a system for local DNS resolution. Also apple addopted this protocol and implemented it in bonjour. Probally a lot of your devices in your network are already using this, eg. Chromecast, NAS server, open elec and arduino yun.

Next to boradcasting the services available on your host you can also reach your device by using the hostname and the .local suffix. E.g. ping monitoring.local

> ping monitoring.local
PING domotiga.local (192.168.2.30) 56(84) bytes of data.
64 bytes from 192.168.2.30: icmp_seq=1 ttl=64 time=3.87 ms
64 bytes from 192.168.2.30: icmp_seq=2 ttl=64 time=42.6 ms
64 bytes from 192.168.2.30: icmp_seq=3 ttl=64 time=66.6 ms

You can enable this on your RPi:

sudo apt-get update
sudo apt-get install avahi-daemon

Go ahead and ping the new .local address on the machine you wish to access the device from! If you installed Itunes on your windows machines you also have the bonjour service installed. If not, just donwload it from the apple website. You can now use this on your CLI but also from your webbrowser. If you want to browse through al available services/clients please install the avahi utils:

apt-get install avahi-utils
avahi-browse -a -t

The browse command will provide you with all available service:

+ wlan0 IPv4 DiskStation Apple File Sharing local
+ wlan0 IPv4 DiskStation _device-info._tcp local
+ wlan0 IPv4 Woonkamer _googlecast._tcp local
+ wlan0 IPv4 monitoring Remote Disk Management local
+ wlan0 IPv4 domotiga Remote Disk Management local

Static on Raspberry PI

Still you can have a good reason not to configure the static IP address via your router, in my case it was a network related project.  Probally you already tried some configuration changes to the /etc/network/interface file. Please undo them. If you did not make a backup, you can use below config:

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d</code>

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual

You can now edit /etc/dhcpcd.conf and please add:

interface eth0
static ip_address=x.x.x.x/24
static routers=x.x.x.x
static domain_name_servers=8.8.8.8

In my case I was connected via SSH, so you can now reboot RPi.