So I am trying to get from my arduino some resource values and some id's , and I can't figure out how to solve this. I haven't played with python, this is my first time, so it is have to be something easy ...
this is my python program
import serial
import requests
import time
import json
ser = serial.Serial('/dev/ttyACM0', 9600, timeout = 1)
i = 0
collected = []
while (i < 15):
line = ser.readline()
if (line[:3] == '***'):
#print line
line = line.strip('*')
tokens = line[:-5].split('|')
#print tokens
list_tuple = (float(tokens[0]) , float(tokens[1]), float(tokens[2]), int(tokens[3]), int(tokens[4]), int(tokens[5]) )
#print list_tuple
collected.append(list_tuple)
i += 1
avg_temp = 0
avg_hum = 0
avg_lum = 0
id_t=0
id_h=0
id_l=0
for c in collected:
avg_temp += c[0]
avg_hum += c[1]
avg_lum += c[2]
id_t = c[3]
id_h = c[4]
id_l = c[5]
avg_temp = avg_temp/len(collected)
avg_hum = avg_hum/len(collected)
avg_lum = avg_lum/len(collected)
print "AVT: %.2f AVH: %.2f AVL: %.2f" % (avg_temp, avg_hum, avg_lum)
id_thing = id_t
id_thing_h = id_h
id_thing_l = id_l
v_type = 'temperature'
v_type_h = 'humidity'
v_type_l = 'luminosity'
# url = .....
#some http post requestes
#....
time.sleep(10)
print "Done"
ser.close()
This is the error :
Traceback (most recent call last):
File "ser.py", line 17, in <module>
list_tuple = (float(tokens[0]) , float(tokens[1]), float(tokens[2]), int(tokens[3]), int(tokens[4]), int(tokens[5]) )
IndexError: list index out of range
And this is the arduino data I try to post
while(1){
float temp, humi;
int err;
if((err=dht11.read(humi, temp))==0)
{
Serial.println();
Serial.print("***");
Serial.print(temp);
Serial.print("|");
Serial.print(humi);
Serial.print("|");
Serial.print(ledPin);
Serial.print("|");
Serial.print(id_temp);
Serial.print("|");
Serial.print(id_hum);
Serial.print("|");
Serial.print(id_lum);
Serial.println();
}
}