I want to automatically post the BMP180 sensor readings to my other blog

    https://gpmweather.noblogs.org

so I researched on how to do it using python. Here are the result.

Requirements:
– Python
– Python XML RPC
– WordPress site
– RPC access to a wordpress site: https:// m y s i t e.noblogs.org/xmlrpc.php

1. You need to download and install python-wordpress-xmlrpc , I installed it using pip:
$ sudo pip install python-wordpress-xmlrpc

Collecting python-wordpress-xmlrpc
Downloading python-wordpress-xmlrpc-2.3.zip
Building wheels for collected packages: python-wordpress-xmlrpc
Running setup.py bdist_wheel for python-wordpress-xmlrpc ... done
Stored in directory: /root/.cache/pip/wheels/e9/09/d8/f36b2110ffb688a6f6cbe138bc48ca7dd95b5082490c9229f4
Successfully built python-wordpress-xmlrpc
Installing collected packages: python-wordpress-xmlrpc
Successfully installed python-wordpress-xmlrpc-2.3

Execute a program using: $ python .//name.py
Create a new python file and test it.
SAMPLE #1

#!/usr/bin/python
#SAMPLE SCRIPT
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
wp = Client('http://mysite.wordpress.com/xmlrpc.php', 'username', 'password')
wp.call(GetPosts())
wp.call(GetUserInfo())
post = WordPressPost()
post.title = 'My new title'
post.content = 'This is the body of my new post.'
post.terms_names = {'post_tag': ['test', 'firstpost'],'category': ['Introductions', 'Tests']}
wp.call(NewPost(post))

 

My bmp180 code to post sensor readings to wordpress:

#!/usr/bin/python
#    Creation date 01/27/2018
#    Reference: https://python-wordpress-xmlrpc.readthedocs.io/en/latest/overview.html#installation
#    Post BMP180 sensor readings to wordpress site using XML-RPC
#    Copyright (C) 2018 Sora
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see .
from libs.BMP085 import BMP085
import os, smbus, spidev, time, datetime
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
bmp = BMP085(0x77)
bus = smbus.SMBus(1)
address = 0x68
bmp = BMP085(0x77, 3)  # ULTRAHIRES Mode
temp = int(bmp.readTemperature())
pressure = int(bmp.readPressure())
altitude = int(bmp.readAltitude())
wp = Client('https://site.noblogs.org/xmlrpc.php', '', '')
wp.call(GetPosts())
wp.call(GetUserInfo())
post = WordPressPost()
post.title  = ('Local BMP180 Sensor Readings - ' + str(datetime.datetime.now()) + ' UTC +08:00')
post.content = ('Barometer/Temperature/Altimeter Sensor (BMP180): ' + '\n' + 'Universal time: ' + str(datetime.datetime.utcnow()) + '\n' + 'Local Time: ' + str(datetime.datetime.now()) + '\n\n'  + 'Temperature: ' + str(temp) + ' deg C \n' + 'Temperature: ' + str((1.8 * temp) + 32) + ' deg F \n' + 'Temperature: ' + str(temp + 273.15) + ' K \n' + 'Temperature: ' + str((1.8 * temp) + 32 + 460) + ' R \n\n' + 'Atmospheric Pressure (Pa): ' + str(pressure) + '\nAtmospheric Pressure (hPa): ' + str(pressure/100.0) + '\nAtmospheric Pressure (mmHg): ' + str(pressure / (100.0 * 1.33322)) + '\nAtmospheric Pressure (inHg): ' + str(pressure * (29.92 / 101325)) + '\n' + '\nAltimeter (m): ' + str(altitude) + '\nAltimeter (ft): ' + str(altitude * (3.28 / 1)))
post.terms_names = {  'post_tag': ['bmp180', 'temperature', 'barometer', 'altimeter', 'sensor', 'rankine', 'fahrenheit', 'celsius', 'centigrade', 'meter', 'feet', 'conversion', 'UTC', 'universal', 'coordinated', 'time', 'hourly', 'update', 'altitude', 'pressure', 'atmosphere', 'inhg' ,'mmhg', 'kelvin', 'pascal','hectopascal', 'degree'], 'category': ['General', 'Weather'] }
post.post_status = 'publish'
wp.call(NewPost(post))

Except where otherwise noted, this work is licensed under Creative Commons Attribution-ShareAlike 4.0 International License (http://creativecommons.org/licenses/by-sa/4.0/).
I hope that this post is useful to you, if you liked this post you may support me via liberapay. Thank you for your support.

Donate using Liberapay