#!/usr/bin/python

import smbus
import time
import os 
import subprocess

bus = smbus.SMBus(1)
address = 0x12

print "Envoi de la valeur 3 indiquant le debut de la demande"
bus.write_byte(address, 3)
# Pause de 1 seconde pour laisser le temps au traitement de se faire
time.sleep(1)

data = ""
for i in range(0, 200):
    data += chr(bus.read_byte(address));
print data

datas = data.split("|")
i = 0
for d in datas:
    i = i + 1
    if i <= 7 :
        print d 
    	print "Send subprocess : curl http://localhost:81/json.htm?type=command&param=udevice&" + d 
	try:
    	    subprocess.Popen(["/usr/bin/curl", "http://localhost:81/json.htm?type=command&param=udevice&" + d ])
            time.sleep(0.5)
	except:
	    print "Error occured " + d
print "Finish"
