Dweepy for Dweet: Difference between revisions
Jump to navigation
Jump to search
| (8 intermediate revisions by the same user not shown) | |||
| Line 12: | Line 12: | ||
[[File:Screenshot 2023-07-24 at 4.28.58 pm.png | 900px]] | [[File:Screenshot 2023-07-24 at 4.28.58 pm.png | 900px]] | ||
= Making a Dweet using Dweety = | |||
* Enter the following code and save the file as dweepy_test.py | * Enter the following code and save the file as dweepy_test.py | ||
| Line 17: | Line 19: | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
# Posting data using dweepy | |||
import dweepy | |||
dweet_dict = {} | dweet_dict = {} | ||
| Line 23: | Line 27: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= Testing to see if the Dweet has been uploaded = | |||
* Open a Web browser | |||
* In the Search Bar enter the url | |||
<syntaxhighlight lang="python"> | |||
https://dweet.io/get/latest/dweet/for/<My_Dweet_address> | |||
</syntaxhighlight> | |||
* Replace <My_Dweet_address> with your own address. | |||
* If the dweet has been committed you should see the following in your browser. | |||
= Retrieving Dweets using Dweepy in Python = | |||
* The following python code pulls information from the dweet and stores the result in '''url''' which is also a dictionary type variable. | * The following python code pulls information from the dweet and stores the result in '''url''' which is also a dictionary type variable. | ||
| Line 28: | Line 45: | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
# Getting a dweet using Dweepy | |||
import dweepy | |||
# Get dweet data | |||
url = dweepy.get_latest_dweet_for('3083-MPPT-Xbee1-test') | url = dweepy.get_latest_dweet_for('3083-MPPT-Xbee1-test') | ||
# Print dweet data set | |||
print(url) | print(url) | ||
# Extract date time from dweet | |||
dict = url[0] | dict = url[0] | ||
longdate = dict['created'] | longdate = dict['created'] | ||
print(longdate) | print(longdate) | ||
# Extract specific data sets from Dweet | |||
voltage = dict['content'][('Volt')] | voltage = dict['content'][('Volt')] | ||
print(f'The voltage is {voltage}') | print(f'The voltage is {voltage}') | ||
| Line 51: | Line 75: | ||
#https://github.com/paddycarey/dweepy - Reference | #https://github.com/paddycarey/dweepy - Reference | ||
# Publish data via a Dweet | |||
dweet_dict = {} | dweet_dict = {} | ||
dweet_dict.update({"Volt": '1000'}) | dweet_dict.update({"Volt": '1000'}) | ||
dweepy.dweet_for('3083-MPPT-Xbee1-test', dweet_dict) | dweepy.dweet_for('3083-MPPT-Xbee1-test', dweet_dict) | ||
# Get data from Dweet | |||
url = dweepy.get_latest_dweet_for('3083-MPPT-Xbee1-test') | url = dweepy.get_latest_dweet_for('3083-MPPT-Xbee1-test') | ||
print(url) | print(url) | ||
| Line 65: | Line 90: | ||
voltage = dict['content'][('Volt')] | voltage = dict['content'][('Volt')] | ||
print(f'The voltage is {voltage}') | print(f'The voltage is {voltage}') | ||
#check dweet with - https://dweet.io/get/latest/dweet/for/<My_Dweet_address> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 78: | Line 105: | ||
dweet_dict.update({"Wattage": '75.0'}) | dweet_dict.update({"Wattage": '75.0'}) | ||
dweet_dict.update({"Temperature": '25.3'}) | dweet_dict.update({"Temperature": '25.3'}) | ||
</syntaxhighlight> | |||
[[File:Screenshot 2023-07-24 at 4.46.44 pm.png | 900px]] | |||
== Full code == | |||
<syntaxhighlight lang="python"> | |||
import dweepy | |||
#https://github.com/paddycarey/dweepy - Reference | |||
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'}) | |||
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}') | |||
current = dict['content'][('Current')] | |||
print(f'The current is {current}') | |||
# check dweet with - https://dweet.io/get/latest/dweet/for/<My_Dweet_address> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 09:42, 10 November 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.
Making a Dweet using Dweety
- 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
# Posting data using dweepy
import dweepy
dweet_dict = {}
dweet_dict.update({"Volt": '1000'})
dweepy.dweet_for('3083-MPPT-Xbee1-test', dweet_dict)
Testing to see if the Dweet has been uploaded
- Open a Web browser
- In the Search Bar enter the url
https://dweet.io/get/latest/dweet/for/<My_Dweet_address>
- Replace <My_Dweet_address> with your own address.
- If the dweet has been committed you should see the following in your browser.
Retrieving Dweets using Dweepy in Python
- 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
# Getting a dweet using Dweepy
import dweepy
# Get dweet data
url = dweepy.get_latest_dweet_for('3083-MPPT-Xbee1-test')
# Print dweet data set
print(url)
# Extract date time from dweet
dict = url[0]
longdate = dict['created']
print(longdate)
# Extract specific data sets from Dweet
voltage = dict['content'][('Volt')]
print(f'The voltage is {voltage}')
Full code
import dweepy
#https://github.com/paddycarey/dweepy - Reference
# Publish data via a Dweet
dweet_dict = {}
dweet_dict.update({"Volt": '1000'})
dweepy.dweet_for('3083-MPPT-Xbee1-test', dweet_dict)
# Get data from Dweet
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}')
#check dweet with - https://dweet.io/get/latest/dweet/for/<My_Dweet_address>
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'})
Full code
import dweepy
#https://github.com/paddycarey/dweepy - Reference
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'})
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}')
current = dict['content'][('Current')]
print(f'The current is {current}')
# check dweet with - https://dweet.io/get/latest/dweet/for/<My_Dweet_address>