Easy Raspberry PI and Sense Hat Datalogger

Decided to have look at the Raspberry PI after reading about the Astro PI project

The Raspberry PI have been around for some time and exist now in several versions. The one I purchased was the Raspberry PI B+

Raspberry PI
Raspberry PI

Together with that I got the Sense Hat module.

Raspberry PI, Sense Hat
Raspberry PI, Sense Hat

Besides these two components, a micro SD (16 GB in my case) is needed and an USB power supply.

Download the linux image and copy it to the SD ( great guide here )

I downloaded NOOBS and installed the image (formatted too many times, really). Then I hooked up the components and inserted the SD card. Added a monitor, keyboard and mouse and finally power.

Initial Raspbian window running on Raspberry PI
Initial Raspbian window running on Raspberry PI

That was easy. I now have a running, working linux system. There were some more steps to do, to get really ready, here is a video of a working system and what the sense HAT module is. (from The Raspberry PI Guy)

I have installed some python packages for interface, database and communication. The process is simple as long as you have connected the Raspberry PI to the net.

Update packages that may be old in the NOOBS image. Open a terminal and enter the following commands

sudo apt-get update
sudo apt-get install sense-hat pillow tightvncserver mysql-server python-mysqldb





I had some issues with the VNC server, when X: is running then display 0 is already in use. (I choose to use display 10 )

One other important step is to set the password for the PI user if you want to use ssh from a remote system.

Now the system is (almost) ready. Some code is needed to read the data from the Sense HAT and write them in the database.

from sense_hat import SenseHat
import time
import MySQLdb
db    = MySQLdb.connect(host="localhost", # your host, usually localhost
user  ="user", # your username
passwd="password", # your password
db    ="database") # name of the data base
cur   = db.cursor()
sense = SenseHat()
temperature = sense.get_temperature()
pressure = sense.get_pressure()
humidity = sense.get_humidity()
# formula see below
temp = round ( 0.0071*temperature*temperature+0.86*temperature-10.0,1)
humidity = round ( humidity*(2.5-0.029*temperature),1)
pressure = round(pressure, 1)
dateTime = time.strftime("%Y%m%d%H%M")
sql="insert into weather(datetime,temp,pressure,humidity) values ('%s','%s','%f','%f','%f');" % (dateTime,temp,pressure,humidity)

Calculation for the temperature. As the sensor is close to processor and led’s the value returned is imprecise. This is the formula to compensate.

It is now possible to get one reading from the Raspberry PI Sense HAT and write it to the database.
201512252355 23.3 978.9 67
201512281740 23.3 972.9 64.1

What Is Internet Of Things

The latest hot topic in IT is the Internet Of Things (IoT), but what is that really?

Simply speaking it is any device that can be connected to the Internet and send or receive commands.

It is not really new, in the sense that we already have many ‘things’ connected to the internet. Computers, disk arrays, printers, bank tellers, video cameras, mobile phones, cars, medical devices, various production machines. The ‘new’ part is that we see a massive number of new Internet enabled devices coming on the market and with them, we are going to make the same errors as we have already done.

Just think about the problems with unauthorised access of your computer, aka, hacking. With the new devices arriving, example intelligent light switches, we will see numerous cases of IoT devices being hacked and abused. One reason is the relative simple designs and interfaces of IoT devices and the cost of building in security.

Hacking is not the only issue facing IoT. Privacy is another. Just like putting your personal data on the Internet and then having to spend a lot of energy to get the ‘wrong’ information out of Google again.

Take the example of temperature control. If you have your house full of temperature sensors and can turn on and off the heating from remote. The sensors will report a daily pattern, like warm between 6am and 8am, warm again from 5pm to 11pm on weekdays and from 7am to 12pm in the weekend. Then you go on vacation and have the heating turned down. The pattern is broken, constant low temperature and that indicates you are not at home. An invitation to burglars.

And what about interfaces? Right now companies like Amazon, MicroSoft, Google, Cisco and others are promoting their API’s which will let the various devices connect to proprietary data collection and monitoring systems.

In the report June 2015  The Internet of Things: Mapping The Value Beyond The Hype by McKinsey, it is found that the economic impact of IoT applications could be from $3.9 trillion to $11.1 trillion per year in 2025.

So it is understandable that all major IT Service Providers are active in this area. This also ties into the offerings of cloud based systems and services. We will be able to collect massive amounts of data, we must store it somewhere and compute it.

But how do we find the relevant data in this wast amount of data. If we take the temperature example, we would want to monitor thresholds and have actions defined when exceeding a threshold. Example, the temperature in a room rises above 38 degree C, 100 degree F. On a summer day it may not be a problem, on a winter day we may have a fire.

The extraction of data will require detailed specifications, in fact this is likely to create way more work than is required at present. So for individual IT people it may be a good thing.

What will happen in the next years is difficult to predict, but it is surely going to be exciting.

Prediction is very difficult, especially about the future.” (unknown)


You do not have sufficient permissions to access this page

Updated a friends blog (new Akismet) and then wanted to add a plugin.

Adding the plugin went ok, but trying to activate it I got the following error

“You do not have sufficient permissions to access this page”

Looked in the database and at permissions, googled all over the place. Loads of 5 years old answers.

Hey, Google, you need to update your databases!!!

Wanted to check if the theme was the issue and found that there was no “Edit” link.

Another round of googling and I came across this on wordpress.org

Disable File Editing
The WordPress Dashboard by default allows administrators to edit PHP files, such as plugin and theme files. This is often the first tool an attacker will use if able to login, since it allows code execution. WordPress has a constant to disable editing from Dashboard. Placing this line in wp-config.php is equivalent to removing the ‘edit_themes’, ‘edit_plugins’ and ‘edit_files’ capabilities of all users:

define(‘DISALLOW_FILE_EDIT’, true);

I changed it to

define(‘DISALLOW_FILE_EDIT’, false);

and Edit menu appeared and I could start the plugins.

Since I will probably forget everything about this in a few days, I added it here, so I can find it again.