def rockBlock(request): sensorName = "sprayWind" now = datetime.datetime.now(timezone.utc) log = "-------------------------------------------------------------------\n" log += "rockBlock at %s \n" % now log += "request method = %s \n" % request.method log += "request body = %s \n\n" % request.body log += "device_type = %s \n" % request.POST.get("device_type") log += "serial = %s \n" % request.POST.get("serial") log += "imei = %s \n" % request.POST.get("imei") log += "momsn = %s \n" % request.POST.get("momsn") log += "transmit_time = %s \n" % request.POST.get("transmit_time") log += "iridium_latitude = %s \n" % request.POST.get("iridium_latitude") log += "iridium_longitude = %s \n" % request.POST.get("iridium_longitude") log += "iridium_cep = %s \n" % request.POST.get("iridium_cep") log += "data = %s \n" % request.POST.get("data") curWind = -1.0 minWind = -1.0 avgWind = -1.0 maxWind = -1.0 curTemp = 0.0 curVoltage = 0.0 try: hexData = request.POST.get("data") jsonData = codecs.decode(hexData, "hex") senml = json.loads(jsonData) log += "SENML = %s \n" % json.dumps(senml) for reading in senml['e']: if reading['n'] == "battery": curVoltage = reading['v'] if reading['n'] == "wind": curWind = reading['v'] if reading['n'] == "gust": maxWind = reading['v'] except Exception as e: log += "Problem parsing the rockblock data. Exception %s \n" % e log += "wind %s (min,avg,max)=%s,%s,%s temp=%s battery=%s \n" % ( curWind, minWind, avgWind, maxWind, curTemp, curVoltage) r = SensorReading(sensorID=sensorName, time=now, info=log, curWind=curWind, minWind=minWind, avgWind=avgWind, maxWind=maxWind, temperature=curTemp, voltage=curVoltage) r.save() log += "\n\n" return HttpResponse()
def rockBlock( request ): sensorName = "sprayWind" now = datetime.datetime.now( timezone.utc ) log = "-------------------------------------------------------------------\n" log += "rockBlock at %s \n" % now log += "request method = %s \n" % request.method log += "request body = %s \n\n" % request.body log += "device_type = %s \n" % request.POST.get("device_type") log += "serial = %s \n" % request.POST.get("serial") log += "imei = %s \n" % request.POST.get("imei") log += "momsn = %s \n" % request.POST.get("momsn") log += "transmit_time = %s \n" % request.POST.get("transmit_time") log += "iridium_latitude = %s \n" % request.POST.get("iridium_latitude") log += "iridium_longitude = %s \n" % request.POST.get("iridium_longitude") log += "iridium_cep = %s \n" % request.POST.get("iridium_cep") log += "data = %s \n" % request.POST.get("data") curWind = -1.0 minWind = -1.0 avgWind = -1.0 maxWind = -1.0 curTemp = 0.0 curVoltage = 0.0 try: hexData = request.POST.get("data") jsonData = codecs.decode( hexData , "hex" ) senml = json.loads( jsonData ); log += "SENML = %s \n" % json.dumps( senml ) for reading in senml[ 'e' ]: if reading['n'] == "battery": curVoltage = reading['v'] if reading['n'] == "wind": curWind = reading['v'] if reading['n'] == "gust": maxWind = reading['v'] except Exception as e: log += "Problem parsing the rockblock data. Exception %s \n"%e log += "wind %s (min,avg,max)=%s,%s,%s temp=%s battery=%s \n"%( curWind, minWind, avgWind, maxWind , curTemp, curVoltage ) r = SensorReading( sensorID=sensorName, time=now, info=log, curWind=curWind, minWind=minWind, avgWind=avgWind, maxWind=maxWind, temperature=curTemp, voltage=curVoltage ) r.save() log += "\n\n" return HttpResponse( )
def cloudMailInJson( request ): sensorName = "sprayWind" now = datetime.datetime.now() log = "cloudMainInJson at %s \n" % now log += "request method = %s \n" % request.method log += "request body = %s \n\n" % request.body curWind = -1.0 minWind = -1.0 avgWind = -1.0 maxWind = -1.0 curTemp = 0.0 curVoltage = 0.0 try: email = json.loads( request.body ) body = email[ 'plain' ] senml = body[ string.find(body,"{") : string.rfind(body,"}")+1 ] sensor = json.loads( senml ) #log += "senml = %s \n" % json.dumps( sensor ) #for reading in sensor[ 'e' ]: # if reading['n'] == "minWind": minWind = reading['v'] # if reading['n'] == "avgWind": avgWind = reading['v'] # if reading['n'] == "maxWind": maxWind = reading['v'] log += "json = %s \n" % json.dumps( sensor ) v = sensor[ 'v' ] ( curWind, minWind, avgWind, maxWind, curTemp, curVoltage ) = v except Exception as e: log += "Problem parsing the email. Exception %s \n"%e log += "wind %s (min,avg,max) = %s,%s,%s temp = %s battery = %s \n"%( curWind, minWind, avgWind, maxWind , curTemp, curVoltage ) r = SensorReading( sensorID=sensorName, time=now, info=log, curWind=curWind, minWind=minWind, avgWind=avgWind, maxWind=maxWind, temperature=curTemp, voltage=curVoltage ) r.save() return HttpResponse( )