Add Date and Time to my Dashboard

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Add Date and Time to my Dashboard

Post by Tom_Henry »

I have created an Adafruit IO desktop using Adafruit’s BME680 sensor and it looks like the attached screen shot.

Now I want to add the Date and Time using Adafruit’s PFC8523.

I have created 2 feeds called date and time that will contain the text fields for the date and time.

Here is the while True: section of my CircuitPython code and the output so far:

while True:
t = rtc.datetime
print()
print("Today is %s: %d/%d/%d" % (days[t.tm_wday], t.tm_mon, t.tm_mday, t.tm_year))
print("The time is %d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec))
print()
print("\nTemperature: %0.2f C" % bme680.temperature)
print("Temperature: %0.2f F" % F)
print("Gas: %d ohm" % bme680.gas)
print("Humidity: %0.2f %%" % bme680.relative_humidity)
print("Pressure: %0.2f hPa" % bme680.pressure)
print("Pressure: %0.2f psi" % psi)
print("Altitude = %0.2f meters" % bme680.altitude)

time.sleep(60)
# publish to adafruit io
io.publish("temperature", F)
# io.publish("gas", bme680.gas)
io.publish("humidity", bme680.relative_humidity)
io.publish("pressure", psi)
io.publish("altitude", bme680.altitude)

Output for the above:

Today is Sunday: 6/26/2021
The time is 20:26:14

Temperature: 28.33 C
Temperature: 80.62 F
Gas: 56887 ohm
Humidity: 41.00 %
Pressure: 1000.76 hPa
Pressure: 14.51 psi
Altitude = 104.54 meters

I need some help on creating a text string for the date and time.

Would appreciate any ideas or suggestions you might have.

Thanks,

Tom Henry
Attachments
Date and Time.png
Date and Time.png (501.79 KiB) Viewed 172 times

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Add Date and Time to my Dashboard

Post by brubell »

I'd save the print statement:

Code: Select all

print("Today is %s: %d/%d/%d" % (days[t.tm_wday], t.tm_mon, t.tm_mday, t.tm_year))
as a string like:

Code: Select all

todays_date = "%s: %d/%d/%d" % (days[t.tm_wday], t.tm_mon, t.tm_mday, t.tm_year)
Then, call io.publish with a new feed for storing the date:

Code: Select all

io.publish("newDateFeed", todays_date)
And do the same for time.

User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Re: Add Date and Time to my Dashboard

Post by Tom_Henry »

Monday

Thank You!

Now my Dashboard is complete with the date and time.

Here is my code:

while True:
t = rtc.datetime
# print(t) # uncomment for debugging
print()
print("Today is %s: %d/%d/%d" % (days[t.tm_wday], t.tm_mon, t.tm_mday, t.tm_year))
todays_date = "%s: %d/%d/%d" % (days[t.tm_wday], t.tm_mon, t.tm_mday, t.tm_year)
print("The time is %d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec))
todays_time = "%d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
print("\nTemperature: %0.2f C" % bme680.temperature)
print("Temperature: %0.2f F" % F)
print("Gas: %d ohm" % bme680.gas)
print("Humidity: %0.2f %%" % bme680.relative_humidity)
print("Pressure: %0.2f hPa" % bme680.pressure)
print("Pressure: %0.2f psi" % psi)
print("Altitude = %0.2f meters" % bme680.altitude)

time.sleep(60)
# publish to adafruit io
io.publish("date", todays_date)
io.publish("time", todays_time)
io.publish("temperature", F)
# io.publish("gas", bme680.gas)
io.publish("humidity", bme680.relative_humidity)
io.publish("pressure", psi)
io.publish("altitude", bme680.altitude)

Tom Henry
Attachments
Date and Time.png
Date and Time.png (494.2 KiB) Viewed 156 times

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”