def oldinsertIntoWixeldata_(data) :
	
	if sensor.SensorisActive():
		CurSensor=sensor.currentSensor()
		print "CurSensor->" + str(CurSensor['started_at'])
		TimeDelta=((long(data['CaptureDateTime'])-long(CurSensor['started_at']))*1.0)/1000/60/60
		Adjusted_raw=xdriplib.calculateAgeAdjustedRawValue(TimeDelta,int(data['RawValue']))
		print "BGReadings AgeAdjustedRaw 		-> " + str(Adjusted_raw)
		Adjusted_raw=xdriplib.calculateAgeAdjustedRawValue(TimeDelta,int(data['RawValue']))
	else:
		print "No Sensor Active"
		Adjusted_raw=0
		
	conn = sqlite3.connect(db.openapsDBName)
	sql='insert into ' + db.tableNameWixeldata
	sql+='(TransmitterId, CaptureDateTime, RelativeTime, ReceivedSignalStrength, RawValue, TransmissionId, BatteryLife, UploadAttempts, Uploaded, UploaderBatteryLife, FilteredValue, age_adjusted_raw_value ) VALUES ('
	sql+="  '" + str(data['TransmitterId']) + "'"
	sql+=', ' + str(data['CaptureDateTime']) 
	sql+=', ' + str(data['RelativeTime']) 
	sql+=', ' + str(data['ReceivedSignalStrength'])
	sql+=', ' + str(data['RawValue']) 
	sql+=', ' + str(data['TransmissionId']) 
	sql+=', ' + str(data['BatteryLife']) 
	sql+=', ' + str(data['UploadAttempts']) 
	sql+=', ' + str(data['Uploaded']) 
	sql+=', ' + str(data['UploaderBatteryLife']) 
	sql+=', ' + str(Adjusted_raw)
	sql+=', ' + str(data['FilteredValue']) + ' )'
	#print "(BGReadings)(insertIntoWixel)  SQL->" + sql
	conn.execute(sql)
	conn.commit()
	print "Records created successfully";
	conn.close()
Example #2
0
def oldtest_():

    mydata = {
        "_id": 1,
        "TransmitterId": "66PNX",
        "CaptureDateTime": 0,
        "RelativeTime": 0,
        "ReceivedSignalStrength": 0,
        "RawValue": 0,
        "TransmissionId": 0,
        "BatteryLife": 0,
        "UploadAttempts": 0,
        "Uploaded": 0,
        "UploaderBatteryLife": 0,
        "FilteredValue": 0
    }

    mydata['CaptureDateTime'] = long(time.time())
    mydata['RelativeTime'] = 2121313
    mydata['RawValue'] = "155000"

    mydata['FilteredValue'] = "155000"
    mydata['BatteryLife'] = "240"
    mydata['TransmitterId'] = "00000"
    mydata['ReceivedSignalStrength'] = 0
    mydata['TransmissionId'] = 0
    print "Time adjusted raw" + str(
        xdriplib.calculateAgeAdjustedRawValue(5, 155000))

    insertIntoWixeldata(mydata)
Example #3
0
def oldinsertIntoWixeldata_(data):

    if sensor.SensorisActive():
        CurSensor = sensor.currentSensor()
        print "CurSensor->" + str(CurSensor['started_at'])
        TimeDelta = (
            (long(data['CaptureDateTime']) - long(CurSensor['started_at'])) *
            1.0) / 1000 / 60 / 60
        Adjusted_raw = xdriplib.calculateAgeAdjustedRawValue(
            TimeDelta, int(data['RawValue']))
        print "BGReadings AgeAdjustedRaw 		-> " + str(Adjusted_raw)
        Adjusted_raw = xdriplib.calculateAgeAdjustedRawValue(
            TimeDelta, int(data['RawValue']))
    else:
        print "No Sensor Active"
        Adjusted_raw = 0

    conn = sqlite3.connect(db.openapsDBName)
    sql = 'insert into ' + db.tableNameWixeldata
    sql += '(TransmitterId, CaptureDateTime, RelativeTime, ReceivedSignalStrength, RawValue, TransmissionId, BatteryLife, UploadAttempts, Uploaded, UploaderBatteryLife, FilteredValue, age_adjusted_raw_value ) VALUES ('
    sql += "  '" + str(data['TransmitterId']) + "'"
    sql += ', ' + str(data['CaptureDateTime'])
    sql += ', ' + str(data['RelativeTime'])
    sql += ', ' + str(data['ReceivedSignalStrength'])
    sql += ', ' + str(data['RawValue'])
    sql += ', ' + str(data['TransmissionId'])
    sql += ', ' + str(data['BatteryLife'])
    sql += ', ' + str(data['UploadAttempts'])
    sql += ', ' + str(data['Uploaded'])
    sql += ', ' + str(data['UploaderBatteryLife'])
    sql += ', ' + str(Adjusted_raw)
    sql += ', ' + str(data['FilteredValue']) + ' )'
    #print "(BGReadings)(insertIntoWixel)  SQL->" + sql
    conn.execute(sql)
    conn.commit()
    print "Records created successfully"
    conn.close()
def oldtest_():

	mydata = {"_id":1,"TransmitterId":"66PNX","CaptureDateTime":0,"RelativeTime":0,"ReceivedSignalStrength":0,"RawValue":0,"TransmissionId":0,"BatteryLife":0,"UploadAttempts":0,"Uploaded":0,"UploaderBatteryLife":0,"FilteredValue":0 }
		
	mydata['CaptureDateTime']=long(time.time())
	mydata['RelativeTime']=2121313
	mydata['RawValue']="155000"

	mydata['FilteredValue']="155000"
	mydata['BatteryLife']="240"
	mydata['TransmitterId']="00000"
	mydata['ReceivedSignalStrength']=0
	mydata['TransmissionId']=0
	print "Time adjusted raw" + str(xdriplib.calculateAgeAdjustedRawValue(5,155000))
		
	insertIntoWixeldata(mydata)
Example #5
0
def serialthread(dummy):
    global mydata
    global BG
    global LASTBG
    print "start serial com"
    firstrun=True 
    while 1:
        try:
            # sometimes the wixel reboots and comes back as a different
            # device - this code seemed to catch that happening
            # more complex code might be needed if the pi has other
            # ACM type devices.
            
            ser = serial.Serial('/dev/ttyMFD2', 9600)
            serial_line="00000"
			
            if (firstrun==False):
                serial_line = ser.readline()
                print "Laenge->" + str(len(serial_line))
                print "Daten Empfangen->" + ":".join("{:02x}".format(ord(c)) for c in serial_line)
                if ord(serial_line[0])>len(serial_line):
                    print "Huston wir haben ein Prob"
                    serial_line="00000"
					
            else:
                print "Startup Transmitter ID senden ->" + str(my_TransmitterID)
                send_TID_wixel(ser,my_TransmitterID)
                firstrun=False

            if ((serial_line[1]=="\xf1")):
                print "Beacon Empfangen!!"
                send_TID_wixel(ser,my_TransmitterID)
                # Testdaten
                #mydata['CaptureDateTime']=str(int(time.time()))+"000"
                #mydata['RelativeTime']="0"
                #mydata['RawValue']="155000"
                
                #mydata['FilteredValue']="155000"
                #mydata['BatteryLife']="240"
                #mydata['TransmitterId']="00000"
                #mydata['ReceivedSignalStrength']=0
                #mydata['TransmissionId']=0
                
                # print "Time adjusted raw" + str(xdriplib.calculateAgeAdjustedRawValue(5,155000))
                # 1,080-80,36
	
            if (serial_line[1]=="\x00") and (len(serial_line)==18):
                print "Dexcom Daten empfangen"
                # simple space delimited data records
                # update dictionary - no sanity checking here
                #  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17
                # 11:00:00:00:00:00:00:00:00:00:bc:00:de:5e:63:00:01:0a
                # 		 |		  | 		     |  |  |		   | Protokoll Level
                #        |        |              |  |  |-------------Transmitter ID
                #        |        |              |  |----------------Bridge Batterie
                #        |        |              |-------------------Dexcom batterie
                #        |        |----------------------------------Filtered Data
                #		 |-------------------------------------------Raw
                
                				
                mydata['CaptureDateTime']=str(int(time.time()))+"000"
                mydata['RelativeTime']="0"
                mydata['RawValue']=str(int(ord(serial_line[2])+(ord(serial_line[3])*256)+(ord(serial_line[4])*65536)+(ord(serial_line[5])*16777216)))
                
                mydata['FilteredValue']=str(int(ord(serial_line[6])+(ord(serial_line[7])*256)+(ord(serial_line[8])*65536)+(ord(serial_line[9])*16777216)))
                mydata['BatteryLife']=str(ord(serial_line[10]))
                mydata['TransmitterId']=str(int(ord(serial_line[12])+(ord(serial_line[13])*256)+(ord(serial_line[14])*65536)+(ord(serial_line[15])*16777216)))
                mydata['ReceivedSignalStrength']=0
                mydata['TransmissionId']=0
                print "Receive" + json.dumps(mydata)


                send_ACK_wixel(ser)
				
                if wixellib.dexcom_src_to_asc(mydata['TransmitterId'])==my_TransmitterID:
                    print "Neue daten Da !!!!!"
                    
                    BGData=BGReadings_Data()
                    CurSensor=sensor.currentSensor()
                    Calib=calibration_Data()
                    Calib.getlatest()
                    
                    BGData.raw_value=long(ord(serial_line[2])+(ord(serial_line[3])*256)+(ord(serial_line[4])*65536)+(ord(serial_line[5])*16777216))
                    BGData.filtered_value=int(ord(serial_line[6])+(ord(serial_line[7])*256)+(ord(serial_line[8])*65536)+(ord(serial_line[9])*16777216))
                    BGData.raw_timestamp=long(str(int(time.time()))+"000")
					
                    
                    BGData.timestamp = BGData.raw_timestamp
                    BGData.DateTime = datetime.datetime.fromtimestamp((BGData.timestamp/1000)).strftime('%Y-%m-%d %H:%M:%S')
                    print "BGData.Datetime -> " + BGData.DateTime 
                    
                    BGData.slope = Calib.slope
                    BGData.intercept = Calib.intercept
                    BGData.sensor_confidence = Calib.sensor_confidence

                    
                    BGData.age_adjusted_raw_value= xdriplib.calculateAgeAdjustedRawValue(xdriplib.getTimeDelta(BGData,CurSensor),BGData.raw_value)
                    BGData.sensor_age_at_time_of_estimation=CurSensor['started_at']
                    
                    
                    
                    BGData.bg=xdriplib.calcCGMVAL(Calib.slope,Calib.intercept,BGData.age_adjusted_raw_value)
                    #BGData.bg=xdriplib.calcCGMVAL(Calib.slope,Calib.intercept,BGData.filtered_value)
                    print "Calib.slope 					 -> " + str(Calib.slope)
                    print "Calib.intercept 				 -> " + str(Calib.intercept)
                    print "BGData.age_adjusted_raw_value -> " + str(BGData.age_adjusted_raw_value)
                    print "BGData.filtered_value         -> " + str(BGData.filtered_value)
                    
                    print "BGData.bg 					 -> " + str(BGData.bg)
                    print "BGData.bg  (filtered)         -> " + str(xdriplib.calcCGMVAL(Calib.slope,Calib.intercept,BGData.filtered_value))
                    BGData.write2db()
                    
                    mongo_getBGReadings()
                    #mongo_findTreatCall_Calib()
                    
                    xdriplib.find_new_curve()
                    xdriplib.find_new_raw_curve()
                    print "Neue Daten in die DB eingetragen ->  \n";
                    #sendScreen()
					
                else:
                    print "Error Found Wrong ID->"+wixellib.dexcom_src_to_asc(mydata['TransmitterId'])+" MyID-> "+  my_TransmitterID +"\n";
                    send_TID_wixel(ser,my_TransmitterID)

			
        except serial.serialutil.SerialException,e:
            print "Serial exception ",e
            time.sleep(1)
			
        ser.close() 
        time.sleep(6)