Пример #1
0
tw.log.info('---------------------')

while (1):
    tw.log.info('-- top of loop --')

    # get sensor reading and timestamp
    data_value = bb.read_ain2()
    time_stamp = dt.datetime.now().isoformat()

    tw.log.info('data_value = ' + str(data_value))

    # post to nimbits over gprs
    bb.initiate_modem_nimbits(s)
    bb.post_nimbits_gprs(data_value, stream_name, s)
    first_response = bb.parse_response(s)
    bb.write_to_db(time_stamp, data_value, first_response, db_cursor, db_connection)

    # turn GPRS off
    s.write('AT#GPRS=0\r\n')
    time.sleep(5)
    response = bb.pause_and_read_serial(s)
    if bb.is_string_in_response('OK', response):
        tw.log.info('good GPRS off response')
    else:
        tw.log.warning('bad GPRS off response')

    # post to rackspace over HTTP
    bb.post_custom_server_http('kitchen', data_value, time_stamp)

    # sleep for a few minutes
    time.sleep(5*60)
Пример #2
0
import twiggy as tw
import serial
import sqlite3
import datetime as dt
import beaglebone as bb

# database objects
db_connection = sqlite3.connect('./sawtooth.db')
db_cursor = db_connection.cursor()

# setup twiggy logging
tw.quickSetup(file='sawtooth.log')
tw.log.info('starting post_random.py')

nimbits_stream = "Test_Stream_2"
data_value = 0

# sleep for a minute, send random number to pachube in json format
while 1:
    tw.log.info("--- top of loop ---")
    time_stamp = dt.datetime.now()

    tw.log.info("data value = " + str(data_value))

    status_code = bb.post_nimbits_http(nimbits_stream, data_value)

    bb.write_to_db(time_stamp, data_value, status_code, db_cursor, db_connection)

    data_value += 0.1
    time.sleep(60)