Category Archives: free

RMAP – important resource

Weather-Station-128x128I would like to be the first or one of first people quoting it: RMAP project. It is a very interesting initiative for a network of environmental data agents. The acronym stays for Rete di Monitoraggio Ambientale Partecipativo (Environmental and Participated Monitoring Network).

RMAP provides a whole set of – absolutely open source – tools, from hardware sensors up to web server for data gathering and distributing.

I am sure you will hear again about it. For the meanwhile… stay in touch.

Advertisements

Raspberry Pi: how to read pin status without shutting it down in Python

From now on, sometimes I would like to publish results of internet searching… that I did NOT find. The results I wanted and I found after just after a long wandering.


 

Raspi-PGB001_reasonably_small When you work with Raspberry Pi, and you are controlling something via output port, say a relay, you can have set a status on it, i.e. you can have put it HIGH, with the usual

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.GPM)
GPIO.setup(25, GPIO.OUT)
GPIO.output(25, HIGH)

Then, some times after, you are willing to know if pin 25 is HIGH o LOW. You have forgot it, or you are not you, but another person willing to know that. Problem: if you set pin 25 as input, you suddenly switch off it. So DO NOT DO this, in the same or another program:

GPIO.setup(25, GPIO.IN)
print GPIO.input(25)

because you will always get a False, at least with default pullups.

Fortunately the answer is simple: just set that pin as output… but read it!

GPIO.setup(25, GPIO.OUT)
print GPIO.input(25)

and you will get a True or a False depending on the real status.

How I met Ubuntu Linux

In the simplest way: I was a lazy Windows user, but curious about Linux. I remembered I had tried something many years before, and I had a vague but not so good memory: yes, pretty, but too difficult, good for initiates.

But when my old PC broke, I changed a lot of hardware, and I didn’t want to fuss over neither complicated and expensive Windows licenses, nor piracy. So I gave Linux a chance: I took the usual (in 2008) Ubuntu CD-ROM sold with a magazine issue and put it in the tray. If you, dear Ubuntu, start smoothly, I will foster you. And that’s what happened.

Everything went fine, no strange questions, no locking. Ubuntu was not so difficult, and much, much more similar to my usual environment than I expected. Five years have passed since then, and now Ubuntu is my usual environment.

So, dear reader, please give you too a chance to Linux: the only thing you really risk, if you reflect, is to find a free and live resource!

Posting 1-wire/RasPi data to Xively without third-party libraries – the simple way

Recently I connected to Xively (you know, the site accepting your environmental data, keeping it and letting you manage it for free – roughly speaking) with Raspberry. I just wanted to send some temperature data with the very famous  1-wire solution. Other help here.

There is a plenty of info about what software to use. I lately fell in love with python, so the language had to be that. If you look for help, you will find that Xively itself and Tinkerforge gives you some handy… pieces of python, and the same with the library owfs  but:

  • Xively gives a library with a full API, very useful but too large for my needs
  • Tinkerforge’s library is based – obviously and rightly – on the hardware they sell. Too large again.
  • OWFS shares – IMHO – the same problems as the Xively one: too large
  • all of them need to be downloaded, installed, etc.
  • really do we need a library? At the end of the day we just must send a PUT call to the HTTP(S) server

So I ended up with a personal version based on the – anyway well done – Tinkerforge version. Mine is “pure python”, using just and only the normal python installation. Probably you still will want to work to refine the code, but that could be considered a good starting point. Here it is:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import socket
import sys
import time
import math
import logging as log
import httplib
import json
import threading

log.basicConfig(level=log.INFO)

MIN_TEMP = -100

def read_temperature():
    # the following code will be different in your case
    tfile = open("/sys/bus/w1/devices/28-0000046ca58d/w1_slave") 
    text = tfile.read()
    tfile.close()

    lines = text.split("\n")

    if lines[0].find("YES") > 0:
        temp = float(lines[1].split(" ")[9][2:])
        temp /= 1000
        return temp
    return MIN_TEMP - 1

class Xively:
    HOST = 'api.xively.com'
    AGENT = "my-agent"
    FEED = 'FEED-ID'
    API_KEY = 'unreadeable-code-given-by-xively'

    def __init__(self):
        self.items = {}
        self.headers = {
            "Content-Type"  : "application/x-www-form-urlencoded",
            "X-ApiKey"      : Xively.API_KEY,
            "User-Agent"    : Xively.AGENT,
        }
        self.params = "/v2/feeds/" + str(Xively.FEED)

        self.upload_thread = threading.Thread(target=self.upload)
        self.upload_thread.daemon = True
        self.upload_thread.start()

    def put(self, identifier, value):
        try:
            _, min_value, max_value = self.items[identifier]
            if value < min_value:                 
                min_value = value             
            if value > max_value:
                max_value = value
            self.items[identifier] = (value, min_value, max_value)
        except:
            self.items[identifier] = (value, value, value)

    def upload(self):
        while True:
            time.sleep(10 * 60) # Upload data every ... min
            if len(self.items) == 0:
                continue

            stream_items = []
            for identifier, value in self.items.items():
                stream_items.append({'id': identifier,
                                     'current_value': value[0],
                                     'min_value': value[1],
                                     'max_value': value[2]})

            data = {'version': '1.0.0',
                    'datastreams': stream_items}
            self.items = {}
            body = json.dumps(data)

            try:
                http = httplib.HTTPSConnection(Xively.HOST)
                http.request('PUT', self.params, body, self.headers)
                response = http.getresponse()
                http.close()

                if response.status != 200:
                    log.error('Could not upload to xively -> ' +
                              str(response.status) + ': ' + response.reason)
            except Exception as e:
                log.error('HTTP error: ' + str(e))

#========================
if __name__ == "__main__":

    log.info('Start')

    xively = Xively()
    i = 0
    while True:
        i += 1
        print('reading ' + str(i))
        temp = read_temperature()
        xively.put('temperature', temp)

        time.sleep(60)

    log.info('End')

My favorite things – what I look for in applications

MaToolsn is a tool-using animal. Without tools he is nothing, with tools he is all  – Carlyle, Thomas

This time I present an important (for me) list of applications. They meet my own criteria for choosing them.

They aim at solving problems already solved for a long time. So they are not experimental, but built on long experience in their field. Hence they are mature to be developed by open source community without depriving the very first developers of their somehow fair reward. But I find quite annoying revenues of a position (so popular here in Italy), even if they are perfectly legitimate.

Take Microsoft Word, good solution for word processing twenty years ago, when alternatives were not so robust and appealing. But more or less around the end of last century novelties ran out: you were able to organize your document in every possible way, with styles, formatting, image insertion, movie insertion (! – do you really need them?)… From then on, it was time to give room to free developing.

Going back to my criteria for applications, the second one is that they run on both Windows AND Linux. I work using both of them, and I don’t want to change my way of work every time I change location.

Interestingly, I discovered that – nowadays – finding solutions meeting my criteria is really easy!

ownCloud… not yet cloud

ownCloud logo

It’s now just one month since I installed ownCloud on my Ubuntu machine. Everything started when I realized I needed something similar to Dropbox, but totally mine. I wanted something faster than it,  with the possibility to grow without a specific limit, and without a monthly fee.
As I wrote in a previous post, I also explored Google Drive, directly comparable with Dropbox. I found that the both of them are very good products, but they share the dependence from internet band, surely narrower than the one in your LAN. So you cannot use them for your movies or CD mp3 version collection. And, yes, I don’t like too much it, having to pay a monthly fee for, say, 300 GB of data, if you really use just a handful of them.
So I wandered a lot around the net to find something similar, but installable in your machine, and I discovered this beautiful open source project, young but not too… unripe.

ownCloud is what I would define a sharing tool. Thanks to web power, it allows you to make your world accessible from everywhere: files, music, pictures, contacts. In concrete terms, it is a web application, based on a web server (usually Apache) and a database (usually mySql), taking care of your files and making them available via a standard browser.

The reason that initially pushed me was that you can install a client in your system allowing you to align a local copy of a directory tree with the one in charge of ownCloud – exactly like Dropbox.

Just to help you to better get the concept, ownCloud is very, very similar to the kind of software mounted on NAS like the QNAP or Synology ones. But in this case you are completely tied to the manifacturer by its proprietary software.

As I said, I installed it on my not-so-performant machine, and I found quite nice that it was not too difficult to install and it performs well.

On the side of access, obviously, if you don’t run a public server (in house or with an internet provider) you can make your private ownCloud accessible by the whole internet via Dynamic DNS.

Finally, a list of service providers exist, that rent ownClouds on their server. I consider it a strong confirmation of robustness of software.

The only funny consideration about ownCloud, at the end, is that – for now – it is not based on cloud! Authors are anyway working actively in order to add this little feature…

Dropbox vs. Google Drive

Nothing is more difficult, and therefore more precious, than to be able to decide – Napoleon Bonaparte

As I wrote in a previous post, I am a happy user of Dropbox long since. I used it as an aligner of directories among my different PCs,  as well as an intelligent (one-month) versioned backup.

I have long been using Google Docs, as a powerful means to share documents and work on them together with some friends or colleague. But while Dropbox merges seamlessly with a traditional approach to documents,  smoothly adding a persistence management, Google Docs is really innovative, and somehow breaks your usual way of working. So, when Google delivered Google Drive (GDr), a clear attempt to enter this segment of services, I was interested in it.

An important note is about Google Docs (texts, spreadsheets, …). I put it this way: Google Docs are just documents based on a new document format. It is proprietary, non-standardized and accessible only through its site. Those are not good credentials for my  judgement. But for the environment they live, they are very useful, anyway.

So now I must decide how to behave with my beloved files: Dropbox or GDr? I have set a table with _my_ main decision criteria:

feature

Dropbox

Google Drive

versioning x (1 month) x (just for Google Docs)
bin x (1 month) x
search engine a simple one Google (!)
Windows and Mac clients x x
Linux client x
synchronized folders and files selection x x
picture and pdf online reading x x
OCR service x
document thumbnails x
online collaboration (document editing sharing, chat) x
LAN syncing x
syncing notification very good less good
free ways
to increase space
Referrals, up to 16GB
security level (in my case and my opinion) enough enough
files grouping physical (directories) logical (tagging and directories)
Online editing
Google Docs documents x
non-Google Docs documents
pure text documents x, with 3-rd party app
Local editing
Google Docs documents
non-Google Docs documents x x
pure text documents x x, with 3-rd party app

As you can see, in my list of criteria I ignored space cost issues, because for my uses the available space is enough for Dropbox, and the cost of 5 $/y for 20 GB in GD is negligible.

So, at the end of the day, the only heavy thing dividing the opponents is IMHO the presence of a tremendously collaborative environment in GDr, but only for Google Docs documents.

So, in my case, given my solid Dropbox file base,  a possible line guide could be still using it for standard documents, and making use of Google Docs only when needing a collaborative environment.

I must agree with many affirming in this case Google (especially thinking  they were starting from a great tool like Google Docs) has offered too little, too late.