Lesson 11 - Tiny House Temperature Monitoring: Difference between revisions
Jump to navigation
Jump to search
(Created page with "= Using Python to Monitor Tiny House Temperature = == Using Python to Download Tiny House Temperature Data == <syntaxhighlight lang="python"> # Get Tiny House data for MPPS import dweepy url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-8-bundoora') print(url) </syntaxhighlight> 900px == Put Temperature Data in Variables == <syntaxhighlight lang="python"> # Get Tiny House data for MPPS import dweepy url = dwee...") |
|||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= | = 1 - Using Python to Download Tiny House Temperature Data = | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
| Line 15: | Line 13: | ||
[[File:Screenshot 2023-12-07 at 8.53.15 am.png | 900px]] | [[File:Screenshot 2023-12-07 at 8.53.15 am.png | 900px]] | ||
= | = 2 - Put Temperature Data in Variables = | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
| Line 36: | Line 34: | ||
[[File:Screenshot 2023-12-07 at 9.01.40 am.png | 900px]] | [[File:Screenshot 2023-12-07 at 9.01.40 am.png | 900px]] | ||
= 3 - Recording Current Date and Time = | |||
<syntaxhighlight lang="python"> | |||
# Get Tiny House data for MPPS | |||
import dweepy | |||
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-8-bundoora') | |||
print(url) | |||
dict = url[0] | |||
internalTemp = dict['content'][('intTemp')] | |||
print(f'The internal temperature is {internalTemp}') | |||
externalTemp = dict['content'][('extTemp')] | |||
print(f'The outside temperature is {externalTemp}') | |||
# Current Date and Time | |||
datetime = dict['content'][('date')] | |||
print(f'The current date_time is {datetime}') | |||
</syntaxhighlight> | |||
[[File:Screenshot 2023-12-07 at 9.07.41 am.png | 900px]] | |||
= 4 - Prepare Data for Saving = | |||
# Get Tiny House data for MPPS | |||
<syntaxhighlight lang="python"> | |||
import dweepy | |||
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-8-bundoora') | |||
print(url) | |||
dict = url[0] | |||
internalTemp = dict['content'][('intTemp')] | |||
print(f'The internal temperature is {internalTemp}') | |||
externalTemp = dict['content'][('extTemp')] | |||
print(f'The outside temperature is {externalTemp}') | |||
# Current Date and Time | |||
datetime = dict['content'][('date')] | |||
print(f'The current date_time is {datetime}') | |||
# Prepare data for saving | |||
data = str(datetime) + "," + str(internalTemp) + "," + str(externalTemp) + "\n" | |||
print(f'The data that will be saved is = {data}') | |||
</syntaxhighlight> | |||
[[File:Screenshot 2023-12-07 at 9.15.23 am.png | 900px]] | |||
= 5 - Saving Data to your Computer = | |||
<syntaxhighlight lang="python"> | |||
# Get Tiny House data for MPPS | |||
import dweepy | |||
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-8-bundoora') | |||
print(url) | |||
dict = url[0] | |||
internalTemp = dict['content'][('intTemp')] | |||
print(f'The internal temperature is {internalTemp}') | |||
externalTemp = dict['content'][('extTemp')] | |||
print(f'The outside temperature is {externalTemp}') | |||
# Current Date and Time | |||
datetime = dict['content'][('date')] | |||
print(f'The current date_time is {datetime}') | |||
# Prepare data for saving | |||
data = str(datetime) + "," + str(internalTemp) + "," + str(externalTemp) + "\n" | |||
print(f'The data that will be saved is = {data}') | |||
# Save data | |||
f = open('/home/pi/MPPS/MPPS_Tiny_House_8_data.txt','a') | |||
f.write(data) | |||
f.close() | |||
print("The data has been saved") | |||
</syntaxhighlight> | |||
[[File:Screenshot 2023-12-07 at 9.19.04 am.png | 900px]] | |||
= Technical Support = | |||
== NodeRED Code == | |||
<syntaxhighlight lang="javascript"> | |||
[ | |||
{ | |||
"id": "2062606fea9508f9", | |||
"type": "tab", | |||
"label": "Tiny House 8", | |||
"disabled": false, | |||
"info": "", | |||
"env": [] | |||
}, | |||
{ | |||
"id": "27798e25b3283306", | |||
"type": "mqtt in", | |||
"z": "2062606fea9508f9", | |||
"name": "whi-tinyhouse-8", | |||
"topic": "#", | |||
"qos": "0", | |||
"datatype": "json", | |||
"broker": "309bdb6af62b946a", | |||
"nl": false, | |||
"rap": true, | |||
"rh": 0, | |||
"inputs": 0, | |||
"x": 100, | |||
"y": 80, | |||
"wires": [ | |||
[ | |||
"bc8307e72be8882c" | |||
] | |||
] | |||
}, | |||
{ | |||
"id": "3b119ec45a0bfd04", | |||
"type": "debug", | |||
"z": "2062606fea9508f9", | |||
"name": "debug 9", | |||
"active": true, | |||
"tosidebar": true, | |||
"console": false, | |||
"tostatus": false, | |||
"complete": "payload", | |||
"targetType": "msg", | |||
"statusVal": "", | |||
"statusType": "auto", | |||
"x": 640, | |||
"y": 220, | |||
"wires": [] | |||
}, | |||
{ | |||
"id": "da62c13bca155cc1", | |||
"type": "function", | |||
"z": "2062606fea9508f9", | |||
"name": "process tiny house 8 data", | |||
"func": "var battery; // battery voltage data\nvar int_humidity; // humidity data from within the sensor housing\nvar ext_temp; // external temperature data\nvar int_temp; // temperature data from within the sensor housing\n\nbattery = msg.payload.uplink_message.decoded_payload.bat;\nint_humidity = msg.payload.uplink_message.decoded_payload.humid;\next_temp = msg.payload.uplink_message.decoded_payload.onewire_temp;\nint_temp = msg.payload.uplink_message.decoded_payload.temp;\n\nmsg.payload = \"bat=\" + String(battery) + \"&\"\n + \"intHumid=\" + String(int_humidity) + \"&\"\n + \"extTemp=\" + String(ext_temp) + \"&\"\n + \"intTemp=\" + String(int_temp) + \"&\"\n + \"date=\" + String(msg.myymd) + \" \" + String(msg.mytimes);\n\nmsg.url = \"https://dweet.io/dweet/for/MPPS-Tiny-House-8-bundoora?\" + msg.payload;\n\n// check dweet with - https://dweet.io/get/latest/dweet/for/<My_Dweet_address>\nreturn msg;", | |||
"outputs": 1, | |||
"noerr": 0, | |||
"initialize": "", | |||
"finalize": "", | |||
"libs": [], | |||
"x": 510, | |||
"y": 140, | |||
"wires": [ | |||
[ | |||
"034c6221e7c582b1" | |||
] | |||
] | |||
}, | |||
{ | |||
"id": "bc8307e72be8882c", | |||
"type": "simpletime", | |||
"z": "2062606fea9508f9", | |||
"name": "", | |||
"mydate": true, | |||
"myymd": true, | |||
"myyear": true, | |||
"mymonth": true, | |||
"mymonthn": true, | |||
"mydom": true, | |||
"mydoy": true, | |||
"myday": true, | |||
"myhourpm": true, | |||
"myhour": true, | |||
"mytime": true, | |||
"mytimes": true, | |||
"myminute": true, | |||
"myminutes": true, | |||
"mysecond": true, | |||
"mymillis": true, | |||
"myepoch": true, | |||
"myrawdate": true, | |||
"mypm": true, | |||
"x": 290, | |||
"y": 80, | |||
"wires": [ | |||
[ | |||
"da62c13bca155cc1", | |||
"e142b286eb6a05f2" | |||
] | |||
] | |||
}, | |||
{ | |||
"id": "e142b286eb6a05f2", | |||
"type": "debug", | |||
"z": "2062606fea9508f9", | |||
"name": "debug 10", | |||
"active": true, | |||
"tosidebar": true, | |||
"console": false, | |||
"tostatus": false, | |||
"complete": "false", | |||
"statusVal": "", | |||
"statusType": "auto", | |||
"x": 480, | |||
"y": 80, | |||
"wires": [] | |||
}, | |||
{ | |||
"id": "034c6221e7c582b1", | |||
"type": "http request", | |||
"z": "2062606fea9508f9", | |||
"name": "dweet tiny house 8 data", | |||
"method": "POST", | |||
"ret": "obj", | |||
"paytoqs": "body", | |||
"url": "", | |||
"tls": "", | |||
"persist": false, | |||
"proxy": "", | |||
"insecureHTTPParser": false, | |||
"authType": "", | |||
"senderr": false, | |||
"headers": [], | |||
"x": 410, | |||
"y": 220, | |||
"wires": [ | |||
[ | |||
"3b119ec45a0bfd04" | |||
] | |||
] | |||
}, | |||
{ | |||
"id": "309bdb6af62b946a", | |||
"type": "mqtt-broker", | |||
"name": "whi-tinyhouse-8", | |||
"broker": "au1.cloud.thethings.network", | |||
"port": "1883", | |||
"clientid": "", | |||
"autoConnect": true, | |||
"usetls": false, | |||
"protocolVersion": "4", | |||
"keepalive": "60", | |||
"cleansession": true, | |||
"birthTopic": "", | |||
"birthQos": "0", | |||
"birthPayload": "", | |||
"birthMsg": {}, | |||
"closeTopic": "", | |||
"closeQos": "0", | |||
"closePayload": "", | |||
"closeMsg": {}, | |||
"willTopic": "", | |||
"willQos": "0", | |||
"willPayload": "", | |||
"willMsg": {}, | |||
"userProps": "", | |||
"sessionExpiry": "" | |||
} | |||
]</syntaxhighlight> | |||
Latest revision as of 22:27, 6 December 2023
1 - Using Python to Download Tiny House Temperature Data
# Get Tiny House data for MPPS
import dweepy
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-8-bundoora')
print(url)
2 - Put Temperature Data in Variables
# Get Tiny House data for MPPS
import dweepy
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-8-bundoora')
print(url)
dict = url[0]
internalTemp = dict['content'][('intTemp')]
print(f'The internal temperature is {internalTemp}')
externalTemp = dict['content'][('extTemp')]
print(f'The outside temperature is {externalTemp}')
3 - Recording Current Date and Time
# Get Tiny House data for MPPS
import dweepy
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-8-bundoora')
print(url)
dict = url[0]
internalTemp = dict['content'][('intTemp')]
print(f'The internal temperature is {internalTemp}')
externalTemp = dict['content'][('extTemp')]
print(f'The outside temperature is {externalTemp}')
# Current Date and Time
datetime = dict['content'][('date')]
print(f'The current date_time is {datetime}')
4 - Prepare Data for Saving
- Get Tiny House data for MPPS
import dweepy
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-8-bundoora')
print(url)
dict = url[0]
internalTemp = dict['content'][('intTemp')]
print(f'The internal temperature is {internalTemp}')
externalTemp = dict['content'][('extTemp')]
print(f'The outside temperature is {externalTemp}')
# Current Date and Time
datetime = dict['content'][('date')]
print(f'The current date_time is {datetime}')
# Prepare data for saving
data = str(datetime) + "," + str(internalTemp) + "," + str(externalTemp) + "\n"
print(f'The data that will be saved is = {data}')
5 - Saving Data to your Computer
# Get Tiny House data for MPPS
import dweepy
url = dweepy.get_latest_dweet_for('MPPS-Tiny-House-8-bundoora')
print(url)
dict = url[0]
internalTemp = dict['content'][('intTemp')]
print(f'The internal temperature is {internalTemp}')
externalTemp = dict['content'][('extTemp')]
print(f'The outside temperature is {externalTemp}')
# Current Date and Time
datetime = dict['content'][('date')]
print(f'The current date_time is {datetime}')
# Prepare data for saving
data = str(datetime) + "," + str(internalTemp) + "," + str(externalTemp) + "\n"
print(f'The data that will be saved is = {data}')
# Save data
f = open('/home/pi/MPPS/MPPS_Tiny_House_8_data.txt','a')
f.write(data)
f.close()
print("The data has been saved")
Technical Support
NodeRED Code
[
{
"id": "2062606fea9508f9",
"type": "tab",
"label": "Tiny House 8",
"disabled": false,
"info": "",
"env": []
},
{
"id": "27798e25b3283306",
"type": "mqtt in",
"z": "2062606fea9508f9",
"name": "whi-tinyhouse-8",
"topic": "#",
"qos": "0",
"datatype": "json",
"broker": "309bdb6af62b946a",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 100,
"y": 80,
"wires": [
[
"bc8307e72be8882c"
]
]
},
{
"id": "3b119ec45a0bfd04",
"type": "debug",
"z": "2062606fea9508f9",
"name": "debug 9",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 640,
"y": 220,
"wires": []
},
{
"id": "da62c13bca155cc1",
"type": "function",
"z": "2062606fea9508f9",
"name": "process tiny house 8 data",
"func": "var battery; // battery voltage data\nvar int_humidity; // humidity data from within the sensor housing\nvar ext_temp; // external temperature data\nvar int_temp; // temperature data from within the sensor housing\n\nbattery = msg.payload.uplink_message.decoded_payload.bat;\nint_humidity = msg.payload.uplink_message.decoded_payload.humid;\next_temp = msg.payload.uplink_message.decoded_payload.onewire_temp;\nint_temp = msg.payload.uplink_message.decoded_payload.temp;\n\nmsg.payload = \"bat=\" + String(battery) + \"&\"\n + \"intHumid=\" + String(int_humidity) + \"&\"\n + \"extTemp=\" + String(ext_temp) + \"&\"\n + \"intTemp=\" + String(int_temp) + \"&\"\n + \"date=\" + String(msg.myymd) + \" \" + String(msg.mytimes);\n\nmsg.url = \"https://dweet.io/dweet/for/MPPS-Tiny-House-8-bundoora?\" + msg.payload;\n\n// check dweet with - https://dweet.io/get/latest/dweet/for/<My_Dweet_address>\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 510,
"y": 140,
"wires": [
[
"034c6221e7c582b1"
]
]
},
{
"id": "bc8307e72be8882c",
"type": "simpletime",
"z": "2062606fea9508f9",
"name": "",
"mydate": true,
"myymd": true,
"myyear": true,
"mymonth": true,
"mymonthn": true,
"mydom": true,
"mydoy": true,
"myday": true,
"myhourpm": true,
"myhour": true,
"mytime": true,
"mytimes": true,
"myminute": true,
"myminutes": true,
"mysecond": true,
"mymillis": true,
"myepoch": true,
"myrawdate": true,
"mypm": true,
"x": 290,
"y": 80,
"wires": [
[
"da62c13bca155cc1",
"e142b286eb6a05f2"
]
]
},
{
"id": "e142b286eb6a05f2",
"type": "debug",
"z": "2062606fea9508f9",
"name": "debug 10",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 80,
"wires": []
},
{
"id": "034c6221e7c582b1",
"type": "http request",
"z": "2062606fea9508f9",
"name": "dweet tiny house 8 data",
"method": "POST",
"ret": "obj",
"paytoqs": "body",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 410,
"y": 220,
"wires": [
[
"3b119ec45a0bfd04"
]
]
},
{
"id": "309bdb6af62b946a",
"type": "mqtt-broker",
"name": "whi-tinyhouse-8",
"broker": "au1.cloud.thethings.network",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]