High Voltage Coils

electrical and mechanical engineering

Home - Tags: python

Tag: python

setup raspberry pi with spdns – secure point DNS

Posted on 14. February 2016 in low voltage experiments

Hi folks,
my ISP is changing my IP address once a day, but still i wanted to connect to my raspberry pi homeserver from the internet. After some experimentation time i found a nice solution to work with.

1.) Register and setup spdns
Register as a new user at spdns.de
Setup a new virtual hostname for example “myhost.spdns.eu”

2.) setup a little python script
I downloaded a script from the user “mmichaa” python_script
and altered the main function of the script

def main(argv):
	if len(argv) != 4:
		print ''
		print "tUSAGE: " + __file__ + ' <hostname> <user> <passwd>'
		print ''
		return None
	hostname = argv[1]
	user = argv[2]
	passwd = argv[3]

to

def main(argv):	
	hostname = 'myhost.spdns.eu'
	user = 'myusername'
	passwd = 'mypassword'

so you do not need to provide the username and password as command line parameters.

3.) setup a cron job to automatically start the script
alter the cron configuration by entering

sudo crontab -e

add a new line at the end of the document

@hourly python /home/pi/spdns-client.py

test the script

sudo /etc/init.d/cron restart

 

Raspberry Pi weather station

Posted on 9. November 2015 in low voltage experiments

Hi folks,
i have the need, to see the temperatures at my home place from a remote location. While surfing the internet, i found a quite simple solution to retrieve the temperature, humidity and air pressure from a sensor hooked up to a raspberry pi.

Hardware needed:

Software architecture:

The data acquisition software is written in python and runs as a service on the raspberry pi. Parts of the software are based on the BME280 script, provided by Shinichi-Ohki link to repository.

Every 10 minutes, data is gathered, and then being transmitted to a database via an URL GET request in the format (mypage.php?temp=25&druck=1028&feuchte=23).

The php script reads out the parameters, provided in the request, does a validity check and if succeeds, inserts the data into a mysql database.

For easy readout of the data, an html site provides an interface to the database. It displays the average temperature of the last 30 minutes and a line chart containing the values of the day.

weather

The software ran in test mode in my home lab for about 2 weeks without problems. Since 8th of November 2015, the hardware was installed at it’s final destination on the attic. The raspberry is housed in a case mounted to the wall on the inside, while the sensor is connected to 1 meter of wiring, residing on the outside.

If this system performs good in real life situations, i am looking forward to improve the software, so i can run a little monthly statistic. But for now all major features i need are implemented.