Wednesday, May 27, 2015

Raspberry PI - Standalone Thingspeak Server installation



UPDATE !! UPDATE !! UPDATE !! UPDATE !!

New fresh install instructions based on the new RASPBIAN Jessie: Raspberry PI2 + Thingspeak Server on RASPBIAN Jessie

-------------------------------------------------------------------------------------------------

Original Article

     As you might read already in my previous  ESP8266 Battery Monitor System  post I was using Thingspeak.com, because of it's flexibility, as a logger for live data uploading.
In the latest week I was exploring deeper Thigspeak capabilities.

   As you know, Thinspeak.com it's a open source project, and you have full access to the project sources on Github 

   What I was interested for was to check the possibility to build/configure and use a standalone Thingspeak Server that can run independently of Internet infrastructure on a small footprint, low power consumption platform.
   The interesting part regarding the Thingspeak Server deployment is the chosen platform, the new RASPBERRY PI 2 Board!


 



    I will present you below the step-by-step process to install your own RPI Thingspeak Server that can be tailored on your own needs and ofcourse, not affected by Internet connection availability and uptime if installed in the same physical location/LAN as your ESP8266 BMS or any sensor grid/array you might want to use with!






INSTALLATION PROCESS:


1.  Install a Raspberry Pi Operating System image on SD card

  •  Download the Raspbian image from RPI website
  •  Write image to SDCard
    For more details please read RPI Install Guide

I was using the Win32DiskImager utility under W7Pro for that, worked like a charm.




2. First RPI RUN with the new SDCard:


  • Inset card in RPI2
  • Boot 
  • From raspi-config:
              - Set to use entire SDcard space
              - Set hostname: RPIMON1
              - Enable SSH Server
              - Write down your new RPI IP: 192.168.2.xx

  • Reboot for apply new hostname & settings
                pi@RPIMON1~$ sudo reboot



3. System Update & required packages install
  • Switch over to SSH remote access with Putty - accept new key


  • Change "pi" account password:
                  pi@RPIMON1~$passwd
  • Set ROOT password, so you can then use root (just for very, very special things!)
              pi@RPIMON1~$sudo passwd root

  • System Update & upgrade  :
              pi@RPIMON1~$sudo apt-get update            
              pi@RPIMON1~$sudo apt-get upgrade          
              pi@RPIMON1~$sudo apt-get dist-upgrade   
              pi@RPIMON1~$sudo sync

  • Reboot:
            pi@RPIMON1~$ sudo reboot


  • Required packages:
           pi@RPIMON1~$sudo apt-get -y install build-essential git mysql-server mysql-client 
                                       libmysqlclient-dev libxml2-dev libxslt-dev libssl-dev libsqlite3-dev


4.  MySQL Database configuration


pi@RPIMON1~$mysql --user=root mysql -p useyourpasswd here
pi@RPIMON1~$mysql> CREATE USER 'thing'@'localhost' IDENTIFIED BY 'speak’;
pi@RPIMON1~$mysql> GRANT ALL PRIVILEGES ON *.* TO 'thing'@'localhost' WITH GRANT OPTION;
pi@RPIMON1~$mysql> commit;
pi@RPIMON1~$mysql> exit;




5.  Ruby & Rails install

          pi@RPIMON1~$wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz
          pi@RPIMON1~$tar xvzf ruby-2.1.5.tar.gz
          pi@RPIMON1~$cd ruby-2.1.5
          pi@RPIMON1~$./configure
          pi@RPIMON1~$make
          pi@RPIMON1~$sudo make install
          pi@RPIMON1~$cd ..
          pi@RPIMON1~$echo "gem: --no-rdoc --no-ri" >> ${HOME}/.gemrc
          pi@RPIMON1~$sudo gem install rails




 6.  THINGSPEAK SERVER INSTALL

pi@RPIMON1~$git clone https://github.com/iobridge/thingspeak.git
pi@RPIMON1~$cp thingspeak/config/database.yml.example thingspeak/config/database.yml
pi@RPIMON1~$cd thingspeak
pi@RPIMON1~$bundle install
pi@RPIMON1~$bundle exec rake db:create

pi@RPIMON1~$mysql --user=root mysql -p
pi@RPIMON1~$mysql> show databases;
pi@RPIMON1~$mysql> exit;





IF all OK continue with loading Thingspeak DB configuration

pi@RPIMON1~$bundle exec rake db:schema:load




RUN the THINGSPEAK SERVER:

pi@RPIMON1 ~/yourthingspeak $ rails server webrick






And the result in Browser:

Running Thingspeak on RPI Board

Create new Thingspeak USER:

Thingspeak Signup page


Create new CHANNEL

Create new channel for ESP8266 BMS data upload


Live Data update:

ESP8266 BMS  - Live data upload


UPDATE !! UPDATE !! UPDATE !! UPDATE !!

New fresh install instructions based on the new RASPBIAN Jessie: Raspberry PI2 + Thingspeak Server on RASPBIAN Jessie




16 comments:

m4rten said...

hello,
did you manually updated gcc?

Unknown said...

Before anything else, on a fresh new RPI install, has been done a System update & upgrade :

pi@RPIMON1~$sudo apt-get update
pi@RPIMON1~$sudo apt-get upgrade
pi@RPIMON1~$sudo apt-get dist-upgrade
pi@RPIMON1~$sudo sync
pi@RPIMON1~$ sudo reboot


m4rten said...

which raspbian version did you use ? wheezy or jessie ?

m4rten said...

Sorry for noob questions but i got so far to this point :

6. THINGSPEAK SERVER INSTALL

pi@RPIMON1~$bundle install

then he stucks at

"Installing libv8 3.16.14.7 with native extensions"

what can i do especially for this thingspeak installation ? I googled but i dont know if these solutions help for this thingspeak installation proces.

Unknown said...

Wheezy

pi@RPIMON1 /etc $ uname -a
Linux RPIMON1 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux

Be sure that you have done system update&upgrade anb installed all required packages before starting installation.

Is RUBY properly installed? Any error ?


m4rten said...

i made these steps with 2 raspberry pi´s. one normal(first version) and one b+ ( no second edition ). On one i installed raspbian Wheezy and on the other i installed Raspbian Jessie. Then i made every step of your Tutorial without any error till that error "Installing libv8 3.16.14.7 with native extensions" .

are there any packages that are not listed on this site which i need ?

m4rten said...

6. THINGSPEAK SERVER INSTALL

pi@RPIMON1~$git clone https://github.com/iobridge/thingspeak.git
pi@RPIMON1~$cp thingspeak/config/database.yml.example thingspeak/config/database.yml
pi@RPIMON1~$cd thingspeak
pi@RPIMON1~$bundle install<---- after this both also stucked and the following came


Gem files will remain installed in /tmp/bundler20151101-2258-siza8vlibv8-3.16.14.13/gems/libv8-3.16.14.13 for inspection.
Results logged to /tmp/bundler20151101-2258-siza8vlibv8-3.16.14.13/extensions/armv6l-linux/2.1.0-static/libv8-3.16.14.13/gem_make.out
An error occurred while installing libv8 (3.16.14.13), and Bundler cannot
continue.
Make sure that `gem install libv8 -v '3.16.14.13'` succeeds before bundling.

sync said...

sudo gem install libv8 -v '3.16.14.13'

sync said...

Without sudo:
gem install libv8 -v '3.16.14.13'
Fetching: libv8-3.16.14.13.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/local/lib/ruby/gems/2.1.0 directory.

With sudo:
sudo gem install libv8 -v '3.16.14.13'
Building native extensions. This could take a while...

Unknown said...

Yes, it might be a permissions issue, how is working with sudo, it's installing OK?

sync said...

Yes it is installed perfectly

sync said...
This comment has been removed by the author.
Unknown said...

Have done a follow-up, a freash new install, this time based on RASPIAN Jessie:
http://www.esp8266-projects.com/2015/11/raspberry-pi2-thingspeak-on-jessie.html

Unknown said...

Everything works fine~!

Unknown said...

thanks you so much!

Unknown said...

Fot those that want to make Things speak systemd service here is the service file. Presumably you run it with pi user

/lib/systemd/system/thingspeak.service
[Unit]
Description=ThingSpeak server
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=pi
Group=pi
WorkingDirectory=/home/pi/thingspeak
ExecStart=/home/pi/thingspeak/bin/rails server webrick
Restart=always

[Install]
WantedBy=multi-user.target

Post a Comment