#! /usr/bin/env python
#  Routine to collect from the AM2315 Temp/Humidity Sensor
#  and pass along to the network for ultimately data display
#
#  borrowed various online routines for AM2315 library
#   31 May 2017   s.poulos
#
import os
import sys
import time
from AM2315 import *

sensor=AM2315()
unit = 1
if len(sys.argv) > 1:
	unit = sys.argv[1]
while 1:

	humid = 999
	while humid > 100:
		humid = sensor.humidity()
	temp = 999
	while temp > 100:
		temp =sensor.temperature()
	today = time.localtime()

	new_rec = "%4d %03d %02d %02d %02d 000 TmpC_Hum_0%c %s %s " % (today.tm_year, today.tm_yday, today.tm_hour, today.tm_min, today.tm_sec,unit,temp, humid)

	print(new_rec)
	time.sleep(2.0)
