Rpi_to_server.py
699 Bytes
#!usr/bin/env python
import serial
import requests
import datetime
date_comp = datetime.datetime.now()
A = str(date_comp.year)
M = str(date_comp.month)
J = str(date_comp.day)
h = str(date_comp.hour)
m = str(date_comp.minute)
s = str(date_comp.second)
date = A + '-' + M + '-' + J + ' ' + h + ':' + m + ':' + s
ser = serial.Serial("/dev/ttyACM0", 9600, timeout=1)
value = ser.readline()
while (value in ['\r', '', '\n']):
value = ser.readline()
data = str(float(value[0:4]))
params = {"ip_address":"172.26.145.111", "numero":"2", "name":"Solaris", "data": data, "date": date}
r = requests.post("http://serveur-etu.polytech-lille.fr/~grouille/PROJET/requests.php", data = params)
print(data)