if __name__ == "__main__":
    addr = 0x20
    if len(sys.argv) == 2:
        if sys.argv[1].startswith("0x"):
            addr = int(sys.argv[1], 16)
        else:
            addr = int(sys.argv[1])

    remove_signal()
    chirp = Chirp(2, addr)

    print chirp
    print "Send data to adafruit.io"
    sys.stdout.flush()
    while True:
        val = chirp.temp()
        time.sleep(0.2)
        hval = chirp.cap_sense()
        if hval < 415:
            water_plant_signal()
        time.sleep(0.2)
        lval = chirp.light()
        print "%d\t%d\t%d" % (hval, val, lval)
        valf = float(val) / 10
        aio.send('temp', valf)
        aio.send('humid', hval)
        aio.send('light-lemon', lval)
        aio.send('light-log10-lemon', log10(lval))
        time.sleep(3600)
def ReadAddressAndPOST(sensor):
    addr = sensor["sensorId"]
    print addr
    chirp = Chirp(1, int(addr, 16))

    # read moisture
    currentValMoisture = chirp.cap_sense()
    print currentValMoisture
    if ("moistureHistory" in sensor):
        historyM = sensor["moistureHistory"]
    else:
        historyM = []
    moisture = {}
    moisture["date"] = str(time.time()),
    moisture["value"] = str(currentValMoisture)
    historyM.append(moisture)
    print historyM

    #read light
    currentValLight = chirp.light()
    print currentValLight
    if ("lightHistory" in sensor):
        historyL = sensor["lightHistory"]
    else:
        historyL = []
    light = {
        "date": str(time.time()),
        "value": str(currentValLight)
    }
    historyL.append(light)
    print historyL

    #read temp
    currentValTemp = chirp.temp()
    print currentValTemp
    if ("tempHistory" in sensor):
        historyT = sensor["tempHistory"]
    else:
        historyT = []
    temp = {
        "date": str(time.time()),
        "value": str(currentValTemp)
    }
    historyT.append(temp)
    print historyT
    headers = {
        'content-type': 'application/json'
    }
    #update all data fields
    js = {
        "sensorId": addr,
        "sensorType": sensor["sensorType"],
        "pinId": sensor["pinId"],
        "turnOnTime": sensor["turnOnTime"],
        "turnOffTime": sensor["turnOffTime"],
        "turnOnMoisture": sensor["turnOnMoisture"],
        "turnOffMoisture": sensor["turnOffMoisture"],
        "moistureHistory": historyM,
        "turnOnLight": sensor["turnOnLight"],
        "turnOffLight": sensor["turnOffLight"],
        "lightHistory": historyL,
        "turnOnTemp": sensor["turnOnTemp"],
        "turnOffTemp": sensor["turnOffTemp"],
        "tempHistory": historyT
    }
    requests.post('http://localhost:3000/sensors/updatesensor',
                  data=json.dumps(js),
                  headers=headers)
Beispiel #3
0
#!/usr/bin/python
import sys, time
import MySQLdb
from chirp import Chirp

addr = 0x20
chirp = Chirp(1, addr)

print "Moisture: " + chirp.cap_sense() + ", Temperature: " + chirp.temp() + ", Light: " + chirp.light()

db = MySQLdb.connect(host="192.163.248.4" ,
			user="******",
			passwd="112131",
			db="raspisen_raspi")


cur = db.cursor()

cur.execute("INSERT INTO soil(cap,temp,light) VALUES("+chirp.cap_sense()+","+chirp.temp()+","+chirp.light()+")")
db.commit()

time.sleep(1000)
Beispiel #4
0
sock = socket()
try:
  sock.connect( (server, port) )
except:
  print "Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT }
  sys.exit(1)

addr = 0x50
hostname = gethostname()

chirp = Chirp(1, addr)

delay = 30

while True:
  lines = []
  #We're gonna report all three loadavg values
  lines.append("chirp.%s.%x.cap_sense %s %d" % (hostname, addr, chirp.cap_sense(), int(time.time()) ))
  lines.append("chirp.%s.%x.temp %s %d" %      (hostname, addr, chirp.temp(),      int(time.time()) ))
  lines.append("chirp.%s.%x.light %s %d" %     (hostname, addr, chirp.light(),     int(time.time()) ))
  message = '\n'.join(lines) + '\n' #all lines must end in a newline
  print "sending message\n"
  print message
  try:
    sock.sendall(message)
  except:
    e = sys.exc_info()[0]
    print e
  sys.stdout.flush()
  time.sleep(delay)