Dweepy for Dweet: Difference between revisions

From Sensors in Schools
Jump to navigation Jump to search
(Created page with "= Dweepy for Dweets = * Dweepy is a library that simplifies posting and fetching data from Dweet = Reference = *[https://www.learnrobotics.org/blog/how-to-fetch-data-from-dweet-io-using-python-tutorial/ How to fetch data from dweet io using python] = Installing Dweepy = * Open the Terminal and enter the command '''pip3 install dweepy''' * To test dweepy close any existing python environments and reopen them (e.g. Thonny). * Then test the library in the Python Shell wit...")
 
Line 65: Line 65:
voltage = dict['content'][('Volt')]
voltage = dict['content'][('Volt')]
print(f'The voltage is {voltage}')
print(f'The voltage is {voltage}')
</syntaxhighlight>
= Adding more data to the dweet_data Dictionary =
* To add more data to the dweet_data dictionary following this code example:
<syntaxhighlight lang="python">
dweet_dict = {}
dweet_dict.update({"Volt": '1000'})
dweet_dict.update({"Current": '3.0'})
dweet_dict.update({"Wattage": '75.0'})
dweet_dict.update({"Temperature": '25.3'})


</syntaxhighlight>
</syntaxhighlight>

Revision as of 06:44, 24 July 2023

Dweepy for Dweets

  • Dweepy is a library that simplifies posting and fetching data from Dweet

Reference

Installing Dweepy

  • Open the Terminal and enter the command pip3 install dweepy
  • To test dweepy close any existing python environments and reopen them (e.g. Thonny).
  • Then test the library in the Python Shell with the command instruction import dweepy
  • If dweepy is correctly installed there will be no errors.

  • Enter the following code and save the file as dweepy_test.py
  • Thh folliwng python code first creates a library, then dweets the library to the dweet-thing named 3083-MPPT-Xbee1-test
dweet_dict = {}
dweet_dict.update({"Volt": '1000'})
dweepy.dweet_for('3083-MPPT-Xbee1-test', dweet_dict)
  • The following python code pulls information from the dweet and stores the result in url which is also a dictionary type variable.
  • Then the individual data components can be extracted, such as Volt
url = dweepy.get_latest_dweet_for('3083-MPPT-Xbee1-test')
print(url)

dict = url[0]
longdate = dict['created']
print(longdate)

voltage = dict['content'][('Volt')]
print(f'The voltage is {voltage}')

Full code

import dweepy

#https://github.com/paddycarey/dweepy - Reference

dweet_dict = {}
dweet_dict.update({"Volt": '1000'})

dweepy.dweet_for('3083-MPPT-Xbee1-test', dweet_dict)

url = dweepy.get_latest_dweet_for('3083-MPPT-Xbee1-test')
print(url)

dict = url[0]
longdate = dict['created']
print(longdate)

voltage = dict['content'][('Volt')]
print(f'The voltage is {voltage}')

Adding more data to the dweet_data Dictionary

  • To add more data to the dweet_data dictionary following this code example:
dweet_dict = {}
dweet_dict.update({"Volt": '1000'})
dweet_dict.update({"Current": '3.0'})
dweet_dict.update({"Wattage": '75.0'})
dweet_dict.update({"Temperature": '25.3'})