Python script automatic start
Posted: Sat Dec 07, 2019 1:28 pm
Hello people,
i need help. I have a python script, located on an USB-stick, the path looks like: /media/pi/USBstick/Data
it needs to starts automaticly AFTER the pi boots up completly.
my script looks like this:
Many epic fails happend when i tried different methods and to end my suffering i am seeking help now in this forum.
i need help. I have a python script, located on an USB-stick, the path looks like: /media/pi/USBstick/Data
it needs to starts automaticly AFTER the pi boots up completly.
my script looks like this:
Code: Select all
#!/usr/bin/python3
import csv
import time
import datetime
import serial
import urllib.request
import sys
import RPi.GPIO as GPIO
SerialIn = serial.Serial("/dev/ttyUSB0",9600)
tvocURL = 'http://api.thingspeak.com/update?api_key=ZD8WW20D5ZD9WXXX&field1='
eco2URL = 'http://api.thingspeak.com/update?api_key=ZD8WW20D5ZD9WXXX&field2='
with open("sensor.csv", "w") as csvfile:
sensorwriter = csv.writer(csvfile)
sensorwriter.writerow(["datetime", "field1", "field2"])
while True:
temp = SerialIn.readline()
temp = temp.decode('utf-8').strip().split(',')
f = urllib.request.urlopen(tvocURL +str(temp[0]))
f.read()
g = urllib.request.urlopen(eco2URL +str(temp[1]))
g.read()
time_now = datetime.datetime.now()
sensorwriter.writerow([time_now, temp[0], temp[1]])
print("{0},{1},{2}". format(time_now, temp[0], temp[1]))
f.close()
g.close()
time.sleep(15)
Many epic fails happend when i tried different methods and to end my suffering i am seeking help now in this forum.