Exemplo n.º 1
0
def save_dht22_values():
    global _temperature, _humidity, _date_save_dht22
    _humidity, _temperature = get_dht22_values()

    _date_save_dht22 = datetime.datetime.utcnow()

    print "Gateway TC : " + _temperature + " C | HU : " + _humidity + " % at " + str(
        _date_save_dht22)

    #save values from the gateway box's DHT22 sensor, if _mongodb is true
    if (_mongodb):
        #saving data in a JSON var
        str_json_data = "{\"th\":" + _temperature + ", \"hu\":" + _humidity + "}"

        #creating document to add
        doc = {
            "type": "DATA_GW_DHT22",
            "gateway_eui": _gwaddr,
            "node_eui": "gw",
            "snr": "",
            "rssi": "",
            "cr": "",
            "datarate": "",
            "time": _date_save_dht22,
            "data": json.dumps(json.loads(str_json_data))
        }

        #adding the document
        add_document(doc)
Exemplo n.º 2
0
def save_dht22_values():
	global _temperature, _humidity, _date_save_dht22
	_humidity, _temperature = get_dht22_values()
	
	_date_save_dht22 = datetime.datetime.now()

	print "Gateway TC : "+_temperature+" C | HU : "+_humidity+" % at "+str(_date_save_dht22)
	
	#save values from the gateway box's DHT22 sensor, if _mongodb is true
	if(_dht22_mongo):
		#saving data in a JSON var
		str_json_data = "{\"th\":"+_temperature+", \"hu\":"+_humidity+"}"
	
		#creating document to add
		doc = {
			"type" : "DATA_GW_DHT22",
			"gateway_eui" : _gwid, 
			"node_eui" : "gw",
			"snr" : "", 
			"rssi" : "", 
			"cr" : "", 
			"datarate" : "", 
			"time" : _date_save_dht22,
			"data" : json.dumps(json.loads(str_json_data))
		}
	
		#adding the document
		add_document(doc)
Exemplo n.º 3
0
def get_dht22():

    try:
        _dht22_mongo = gw_json_array["status_conf"]["dht22_mongo"]
    except KeyError:
        _dht22_mongo = False

    if (_dht22_mongo):
        global add_document
        from MongoDB import add_document

    print "post status get DHT22: get gateway temperature and humidity level"
    #read values from dht22 in the gateway box
    sys.path.insert(0, os.path.expanduser('./sensors_in_raspi/dht22'))
    from read_dht22 import get_dht22_values

    _humidity, _temperature = get_dht22_values()

    _date_save_dht22 = datetime.datetime.now()

    print "post status get DHT22: Gateway TC : " + _temperature + " C | HU : " + _humidity + " % at " + str(
        _date_save_dht22)

    #save values from the gateway box's DHT22 sensor, if _mongodb is true
    if (_dht22_mongo):
        #saving data in a JSON var
        str_json_data = "{\"th\":" + _temperature + ", \"hu\":" + _humidity + "}"

        #creating document to add
        doc = {
            "type": "DATA_GW_DHT22",
            "gateway_eui": _gwid,
            "node_eui": "gw",
            "snr": "",
            "rssi": "",
            "cr": "",
            "datarate": "",
            "time": _date_save_dht22,
            "data": json.dumps(json.loads(str_json_data))
        }

        #adding the document
        add_document(doc)