Example #1
0
from time import sleep

from sensor import SensorServer

if __name__ == '__main__':
    sensor_server = SensorServer()
    sensor_server.daemon = True
    sensor_server.start()

    while True:
        sensor_output = sensor_server.get_sensor_output()
        print sensor_output
        print "Wait for 1 second."
        sleep(1)
from sensor import SensorServer
A = SensorServer()
A.run()
Example #3
0
                        help="specify Bluetooth baud rate in bps")

    args = parser.parse_args()

    # Create a BT server
    uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"
    bt_service_name = "Air Pollution Sensor"
    bt_server = BTServer(uuid, bt_service_name)

    # Create BT server thread and run it
    bt_server_thread = Thread(target=asyncore.loop, name="BT Server Thread")
    bt_server_thread.daemon = True
    bt_server_thread.start()

    # Create sensor server thread and run it
    sensor_server = SensorServer(database_name=args.database_name)
    sensor_server.daemon = True
    sensor_server.start()

    # Create database connection and retrieve its cursor
    try:
        db_conn = sqlite3.connect(args.database_name)
        db_cur = db_conn.cursor()
    except Exception as e:
        logger.error("Error connecting the database {}, reason: {}".format(
            args.database_name, e.message))

    while True:
        msg = ""
        sensor_output = sensor_server.get_sensor_output()
        epoch_time = int(time())  # epoch time
Example #4
0
    ##################### I N I T ##################################################
    #######for server
    uuid = "fa87c0d0-afac-11de-8a39-0800200c9a66"
    service_name = "Air Pollution Sensor"
    bt_server = BTServer(uuid, service_name)
    ######## db name
    db_name = "sensor.db"
    ######## UDOO mac addr
    udoo_mac = '4e:71:9e:8c:3f:ee'
    ##################### BT SERVER THREAD ##########################################
    bt_server_thread = Thread(target=asyncore.loop, name="BT Server Thread")
    bt_server_thread.daemon = True
    bt_server_thread.start()
    ###################### SENSOR THREAD ############################################
    sensor_server = SensorServer(db_name)
    sensor_server.daemon = True
    sensor_server.start()
    ##################### ROAD THE DB ################################################

    try:
        db_conn = sqlite3.connect(db_name)
        db_cur = db_conn.cursor()
    except Exception as e:
        print "ERROR (sensor.py): {}".format(repr(e))
        #print out error using repr(e)
###################### INIT SOMTHING ############################################
    send_status = 0
    reg_s = {'MAC': ''}
    reg_j = json.dumps(reg_s)
    ###################### ROOF START ###############################################