Click for weather forecast
If you have no own weather station but are interested in local weather data then weather data from Weather Underground (wunderground) can help to close this gap.
I built three small scripts to ask wunderground for data, send the to the thingspeak server for visualization and cover both scripts. You will find them on Github for download.
wunderweather.py asks Wunderground for locale weather data. Local means here Altendorf in Switzerland.
# Reading weather data from wunderground network
f = urllib2.urlopen('http://api.wunderground.com/api/a50aba1a6119706f/geolookup/conditions/q/Switzerland/Altendorf.json')
json_string = f.read()
parsed_json = json.loads(json_string)
location = parsed_json['location']['city']
temp_c = parsed_json['current_observation']['temp_c']
rel_hum = parsed_json['current_observation']['relative_humidity']
weather = parsed_json['current_observation']['weather']
station = parsed_json['current_observation']['station_id']
updated = parsed_json['current_observation']['observation_time_rfc822']
print("Current temperature in %s is: %s *C" % (location, temp_c))
print("Current relative humidity is: %s %%" % (rel_hum))
print("Weather is %s " % (weather))
print("Weather station is %s" % (station))
print("Last updated: %s" % (updated))
f = open("TEMP","w")
f = open("HUMI","w")
thingspeak.sh sends temperature und humidity to the Thingspeak server:
echo "Send data to Thingspeak Server"
read TEMP < /home/TEMP
echo "Temperature = $TEMP *C"
read HUMI < /home/HUMI echo "Rel. Humidity = $HUMI %" curl --data \ "api_key=$api_key&field1=$TEMP&field2=$HUMI&field3=$DATE" \ https://api.thingspeak.com/update > log 2>&1
As you can see from both scripts you need access data for the APIs. Therefore you have to register on both services.
The last script weather.sh covers both calls. That’s all:
Push messages can help to get status info of IoT nodes which can not always connected directly. There are different services that are suitable for sending push messages. A very simple way to integrate the sending of push messages into an application program is pushover (https://pushover.net/). You have to create an account there and register your application. After that you will get credentials for connecting to the Pushover server.
For Android devices receiving the Pushover messages you will find a Pushover Client in Google Play Store. After installation and login with the Pushover credentials you can register this client on server side too
After starting with Onion Omega2+ I want to get some information of the uptime of the system to check stability. For this purpose I installed cURL and Pushover and call a Shell script as cronjob.
Here are the steps to follow after registration at Pushover:
opkg install curl
The following script sends a message to the Pushover server and the server prepares the messages to the registered devices.
$ curl –s \
--form-string "token=<APP_TOKEN> \
--form-string "user=<USER_TOKEN> \
--form-string "message=<MESSAGE> \
This command I embedded into a further Shell script OmegaPushover.sh which can send messages in the following format:
$ ./OmegaPushover.sh "This is a message"
To include into the crontab I wrote a further script monitoring_uptime.sh.
uptime > UPT
echo -n Uptime:
Both scripts you will find in my Onion Omega repository.
Here is a screenshot of a received Pushover message from my Android phone.
MQTT is an important protocol for data exchange in IoT networks.The communication between the producer of data (publisher) and the consumer of that data (subscriber) goes over an MQTT Broker always.
There are some free MQTT Broker around. I use CloudMQTT of the Swedish company 84codes AB for my applications. CloudMQTT are Mosquitto server in the cloud.
Whats’s to do on Onion Omega2+ side after creating an MQTT account?
We have to install Mosquitto.
opkg install mosquitto mosquitto-client libmosquitto
I have here several temperature sensors in a controller network that send temperature and humidity data to the CloudMQTT broker.
To subscribe these data the follwoing subscribe command is needed on Onion Omega2+:
mosquitto_sub -h m20.cloudmqtt.com -u "ra.....id" -P "ah.....8JS" -p 12394 -t "DHT11/+/#" -v
You must change the user (-u), password (-P), and port (-p) to the login data of your broker account.
As you can see from the following screenshot it’s winter in Switzerland with around 2°C and 80 % rel. Humidity.
To get an idea what’s in the package I used a small Shell script to get some information about the Omega2+ device. Here you can see the output of my script. The file is in the repository https://github.com/ckuehnel/Omega2.
Yesterday I got an Omega2+ incl. Power Dock. Now, if there is time over Christmas I will start to discover this nice part.
A lot of information can be found on Onion’2 Wiki.