Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- from urllib.request import urlopen
- import json
- import subprocess
- import requests
- import random
- import sys
- import os
- import time
- import datetime
- import MySQLdb as my
- import psutil
- db = my.connect(host=".com",
- user="",
- passwd="",
- db="test"
- )
- cursor = db.cursor()
- def getCPUtemperature():
- res = os.popen('vcgencmd measure_temp').readline()
- return(res.replace("temp=","").replace("'C\n",""))
- r = requests.get('http://ipv4.icanhazip.com/')
- p = r.text
- name = "Rockland, ME"
- now = datetime.datetime.now()
- currentTime = datetime.datetime.now()
- temp = float(getCPUtemperature())
- temp = (temp * 1.8) + 32
- boot = datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S")
- id = 10008
- sql = "insert into test VALUES(NULL, '%s', '%s', '%s', '%s', '%s')" % \
- (name, temp , boot, currentTime, p)
- number_of_rows = cursor.execute(sql)
- db.commit()
- db.close()
- #### Edit crontab -e #### / Dont use sudo crontabe
- */1 * * * * sh /home/pi/python/status.sh >/home/pi/logs/cronlog1 2>&1
- ######################
- ###### status.sh ######
- #!/bin/sh
- # launcher.sh
- # navigate to home directory, then to this directory, then execute python scrip$
- sudo python3 /home/pi/python/sensors.py
- ############################
- Required Installs
- sudo pip3 install mysqlclient
- sudo pip3 install psutil
- sudo apt-get update
- sudo apt install mariadb-server
- mkdir python
- mkdir logs
- sudo nano python/sensors.py
- sudo nano python/status.sh
- sudo nano /etc/motd
Add Comment
Please, Sign In to add comment