Tweet-a-watt Calibration

XBee projects like the adapter, xBee tutorials, tweetawatt/wattcher, etc. from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
lazboy0284
 
Posts: 1
Joined: Sat Jun 06, 2009 9:40 am

Re: Tweet-a-watt Calibration

Post by lazboy0284 »

I don't know Python that well, but what I determined to cause the divide by 0 error was when the history.dayswatthr=0 was set. I've attached a portion of my code below that shows how I overcame this, by placing the clear after the twitter occurred.

Code: Select all

    # We're going to twitter at midnight, 8am and 4pm
    # Determine the hour of the day (ie 6:42 -> '6')
    currhour = datetime.datetime.now().hour
    # twitter every 8 hours
    if (((time.time() - twittertimer) >= 3660.0) and (currhour % 8 == 0)):
        print "twittertime!"
        twittertimer = time.time();
        if not LOGFILENAME:
            message = appengineauth.gettweetreport()
            print "getting tweet report\n"
        else:
            # sum up all the sensors' data
            wattsused = 0
            whused = 0
            print time.time()
            for history in sensorhistories.sensorhistories:
                wattsused += history.avgwattover5min()
                whused += history.dayswatthr
	                
            message = "Currently using "+str(int(wattsused))+" Watts, "+str(int(whused))+" Wh today so far #tweetawatt"
            # write something ourselves
        if message:
            print message
            TwitterIt(twitterusername, twitterpassword, message)
            #clear out Wh history at midnight, after twitter.
            if (currhour == 0):
                history.dayswatthr = 0
Last edited by lazboy0284 on Sat Jun 06, 2009 2:15 pm, edited 1 time in total.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Tweet-a-watt Calibration

Post by adafruit »

thanks, also you can use the "code" button to have your code formatted as you pasted it in

Locked
Please be positive and constructive with your questions and comments.

Return to “XBee products (discontinued)”