Rpi_to_server.py 864 Bytes
#!usr/bin/env python

import serial
import requests
import datetime
import os
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

os.system("ip r | cut -f9 -d' ' > ip_address.txt")

file = open("ip_address.txt", 'r')
ip_address = file.readline()
ip_address = file.readline()[:-1]

num_capteur = int(os.path.abspath(".")[-1])


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": ip_address, "numero": num_capteur, "data": data, "date": date}
r = requests.post("http://projet-p10.plil.fr/requests.php", data = params)
print(data)