Thursday, February 5, 2015

setting up IoT server with ThingSpeak on Ubuntu 12.04

installing IoT server with thingspeak on ubuntu 12.04.

some time back yours truly has did some IoT inspired device, by streaming temperature sensor data using ESP8266 to the Internet; the receiving side of the sensor data is the FREE ThingSpeak server, courtesy of iobridge. details of the IoT streaming data setup here http://shin-ajaran.blogspot.sg/2015/01/iot-streaming-temperature-data-acquired.html


The ability to display IoT sensor data in a chart on the Internet is extremely useful. The following screenshot depicts the "public view" of my thingspeak sensor data chart that can be shared on web presence eg a blog or website; data collected can be used for processing/detecting/predicting. Note the LHS of the chart as compared to the "pattern" on the RHS. analyzing outliers, yummsss.



















The free thingspeak server allows for sensor update once very 15sec per channel ref here: http://community.thingspeak.com/documentation/api/ ; in other words, if a sensor (or many sensors) is required to send data at shorter interval eg every second, the free thingspeak server is not able to accommodate. thanks to open source software by iobridge, humans now can install thingspeak on their own computing resources, and customize according to their requirements.













picture above depict thingspeak server running off a VM on my "server" behind a simple network in my office. It is not publicly accessible.













picture above depict thingspeak server running off a VM on the R&D cloud in T931 behind a myriad of ACLs. It is not publicly accessible.

The step by step guide from the source repo is available here https://github.com/iobridge/thingspeak

The major software components needed on ubuntu 12.04 to use with thingspeak are mysql, ruby, rails, and major pkg updates. Assuming the server is behind a simple network with only a router-to-internet, setting up thingspeak is a breeze. There are open source bash scripts, eg https://gist.github.com/abythell/8225124 to help to manage the installation, originated from this blog post http://angryelectron.com/how-to-install-a-thingspeak-server/ Don't you just love open source software??

The complexity comes when 
1. installing on a VM that sits in the cloud that is behind a myriad of ACLs
2. scaling up the thingspeak server in the cloud as a PAAS, and clustering the resources.

your truly had his fair share of frustrating after office hours trying to fix some of the installation issues due to the complexity of the network and also the unfamiliarity with ruby, gems, and rails (first time installing it). nonetheless, the main gripe is documented in the gist below which address BADSIG from apt-get update, git to use https, gpgkeys: HTTP fetch error 7: couldn't connect: Network is unreachable, packages cannot be authenticated!, etc.

the screenshot of thingspeak server is running













the expanded installation bash from the user mentioned above is available here
#have to physically connected to the respective AP to use
#T931 cloud thingSpeak1: 172.16.114.166
#http://172.16.114.166:3000
#T1662 thingspeak server: 192.168.1.117:3000
//---error with apt-get----
#remove deb with Failed cond via comment #
sudo nano /etc/apt/sources.list
/----list sw to a file--
dpkg --get-selections > sw_list.txt
//--------------------
https://github.com/iobridge/thingspeak
//----add diff repo-------
#chk ubuntu ver
lsb_release -sc
#need this b4 apt add
sudo apt-get install software-properties-common
sudo apt-get install python-software-properties
#add repo
sudo nano /etc/apt/sources.list
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ precise main
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ precise main
//==============
//--fix BADSIG from apt-get update
cd /var/lib/apt
sudo mv lists lists_bu
sudo mkdir -p lists/partial
sudo apt-get clean all
sudo apt-get update
//----git to use https instead because during bundle install failed
git config --global url."https://".insteadOf git://
//---gem for jquery installed failed-------
gem install jquery-ui-rails -v '5.0.0'
//===========
#do not use aptget to install ruby
#!/bin/bash
# Install Thingspeak server on Ubuntu 12.04 LTS with rvm.
# Andrew Bythell <abythell@ieee.org>
# Install required packages
## upgrade have conflict in /etc/issues, proceed with maintainer's ver
sudo apt-get -y upgrade
#install mysql root:root
sudo apt-get -y install build-essential mysql-server mysql-client libmysqlclient-dev
#install rubygems
sudo apt-get -y install libxml2-dev libxslt-dev git-core curl rubygems
#alt rubygems
sudo apt-get install libxml2-dev libxslt-dev git-core curl rubygems
#alt rubygems u14.04
sudo apt-get install libxml2-dev libxslt-dev git-core curl ruby
sudo apt-get install rubygems-integration
## Install rvm
#err-> gpgkeys: HTTP fetch error 7: couldn't connect: Network is unreachable
gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
#new gpg sig
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
#gpg sig alt that works
command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
#add pubkey manually for rvm
sudo apt-key adv --recv-key --keyserver keyserver.ubuntu.com D39DC0E3
sudo apt-key adv --recv-key --keyserver keyserver.ubuntu.com 409B6B1796C275462A1703113804BB82D39DC0E3
sudo apt-key adv --recv-key --keyserver keyserver.ubuntu.com 40976EAF437D05B5
#with port80 added; doesnt work
sudo apt-key adv --recv-key --keyserver keyserver.ubuntu.com:80 D39DC0E3
#get rvm
\curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
#The following packages cannot be authenticated!libsigsegv2 libgdbm-dev(solved with ap-get update mod)
rvm install ruby-2.1.0
#alt cmd
rvm install 2.1
#git to use https instead because during bundle install failed
git config --global url."https://".insteadOf git://
### Install thingspeak
git clone https://github.com/iobridge/thingspeak.git
cd thingspeak
gem install minitest -v '4.7.5'
gem install json -v '1.8.1'
bundle install
#bundle install --verbose ##to see output of bundle install
#cp then cfg the db params
cp config/database.yml.example config/database.yml
#create mysql db for thingspeak via ruby; pwd muz match for mysql db
rake db:create
rake db:schema:load
#start thingspeak server
rails server
//=====
#start ts server after reboot
source ~/.rvm/scripts/rvm
rails server


now, let's start to do some IoT inspired stuff by streaming some data to thingspeak

2 comments:

gustavomonarin said...

Have u found any difference from the thingspeak.com???


I am currently working on a project where the intenert connection is limmited and a hosted thingspeak would be a great solution however i am with problems to access the apps / react ...

Regards

Hasan Tariq said...

Data is not being Streamed using this process...