Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed some delays

  • Loading branch information...
commit e14afdb502d0040665838e8f6d2c8861c3a72095 1 parent 7b4bd27
@outofjungle authored
Showing with 27 additions and 13 deletions.
  1. +27 −13 rpi/bin/sync2serial
View
40 rpi/bin/sync2serial
@@ -43,6 +43,19 @@ if __name__ == '__main__':
action="store_true"
)
+ parser.add_argument(
+ '--once',
+ help='run once',
+ action="store_true"
+ )
+
+ parser.add_argument(
+ '--delay',
+ help='refresh delay',
+ type=int,
+ default=5
+ )
+
args = parser.parse_args()
logging.basicConfig(
@@ -57,6 +70,16 @@ if __name__ == '__main__':
FEED = config.get( 'cosm', 'FEED_ID' )
API_URL = 'http://api.cosm.com/v2/feeds/{feed}.json'.format(feed = FEED)
+ ser = serial.Serial(
+ port = args.device,
+ baudrate = 9600,
+ parity = serial.PARITY_NONE,
+ stopbits = serial.STOPBITS_ONE,
+ bytesize = serial.EIGHTBITS
+ )
+ time.sleep(1)
+
+
while ( True ):
request = urllib2.Request( API_URL )
@@ -71,20 +94,11 @@ if __name__ == '__main__':
payload = ','.join( payload )
- ser = serial.Serial(
- port = args.device,
- baudrate = 9600,
- parity = serial.PARITY_NONE,
- stopbits = serial.STOPBITS_ONE,
- bytesize = serial.EIGHTBITS
- )
-
- time.sleep(1)
-
logging.debug( 'Sending to {device}: {data}'.format( device = args.device, data = payload ) )
ser.write( '${data}*{checksum}\r\n'.format( data = payload, checksum = checksum( payload ) ) )
- ser.close()
-
- time.sleep( 10 )
+ if ( args.once ):
+ break
+
+ time.sleep( args.delay )
Please sign in to comment.
Something went wrong with that request. Please try again.