Paso 2: Creando el Script de Python (PyCharm)
Instalado PyCharm en yout computadora, copiar y pegar el siguiente código:
>>> Todo lo que debajo de esta línea copia <<<
import jsonimport sys import urllib2 import time import serial # Configurations ping_server = 30 jenkins_jobs=["Your Job Name Here"] ser = serial.Serial('COM3', 9600) # Arduino Configuration SUCCESS = 'b' FAILURE = 'r' BUILDING = 'a' UNSTABLE = 'y' time.sleep(5) def get_status(jobName): jenkinsUrl = "http://Your Jenkins Server:Port/job/" try: jenkinsStream = urllib2.urlopen( jenkinsUrl + jobName + "/lastBuild/api/json" ) except urllib2.HTTPError, e: print "URL Error: " + str(e.code) print " (job name [" + jobName + "] probably wrong)" sys.exit(2) try: buildStatusJson = json.load( jenkinsStream ) except: print "Failed to parse json" sys.exit(3) return jobName,buildStatusJson["timestamp"], buildStatusJson["result"], while(1): for job in jenkins_jobs: status = get_status(job) # print status[0], status[2] if status[2] == "UNSTABLE": ser.write(UNSTABLE) elif status[2] == "SUCCESS": ser.write(SUCCESS) elif status[2] == "FAILURE": ser.write(FAILURE) elif status[2] == None: ser.write(BUILDING) time.sleep(ping_server)
Notas:
En Windows 7, el número de puerto COM de Arduinos puede verse en el administrador de dispositivos.