-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWeatherClientScript.py
41 lines (33 loc) · 1.47 KB
/
WeatherClientScript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys
import json
import time
import os
import IOTAWeatherNode as Node
#Write here the IOTA adress of the Weather Node.
#address="RVORZ9SIIP9RCYMREUIXXVPQIPHVCNPQ9HZWYKFWYWZRE9JQKG9REPKIASHUUECPSQO9JT9XNMVKWYGVA"
address=input("Address IOTA Node? ")
#Enter here your seed.
seed=input("Address IOTA Node Seed? ")
promotionText="This is my promotion!"
commandWeather="{'command':'getWeather'}"
commandPromotion="{'command':'sendPromotion','promotion':'"+promotionText+"'}"
#If you want to request the actuel Weather set command=commandWeather
#If you want to send a Promotion to the Weather Node type command=commandPromotion
#command=commandPromotion
command=commandWeather
transactionOld=Node.IOTA.searchNewTransaction2(seed)
print("Node.IOTA.sendMessage(self,"+ seed +","+ address+","+ command+", '1'")
Node.IOTA.sendMessage(seed, address, command, '1')
print("Succesfully send request.")
if(command=commandWeather):
print("Waiting until the Weatehr Node send back the Weather Infos.")
while True:
time.sleep(5)
self.transaction=Node.IOTA.searchNewTransaction2(self.seed)
if self.transactionOld!=self.transaction:
self.transactionOld=self.transaction
break
commandRecived=Node.IOTA.searchMessage(transaction)
commandRecived=commandRecived.replace('\'','\"')
jsonData=json.loads(commandRecived)
print("Temperatur: "+jsonData['temperature'+"Humidity: "+jsonData['humidity']+"Pressure: "+jsonData['pressure'])