How to connect a switch button to Huzzah:
pin 2 of button → ground
pin 14 (or any number pin) → pin 1 of button
pin 1 of button → resistor
resistor → 3v
How to send button through thingworx: (PUT function)
import urequests
from machine import Pin
from utime import sleep
url = 'http://pp-1804271345f2.portal.ptc.io:8080/Thingworx/Things/CEEO_Summer/Properties/'
headers = {
'Content-Type':'application/json',
'Accept':'application/json',
'appKey':'f76e9513-0bbc-4b33-af7f-09e5ea959504'
}
while True:
pin14 = Pin(14,Pin.IN)
button = (pin14.value())
print(button)
payload = {'ptest':str(button)}
print(payload)
urequests.put(url+'*',headers=headers,json=payload)
sleep (.5)
*This code is sending to the "thing" titled CEEO_Summer and the "property" titled ptest
How to receive button through thingworx: (GET function)
import urequests
import ujson
import machine
# Info
url = 'http://pp-1804271345f2.portal.ptc.io:8080/Thingworx/Things/CEEO_Summer/Properties/'
headers = {
'Content-Type':'application/json',
'Accept':'application/json',
'appKey':'f76e9513-0bbc-4b33-af7f-09e5ea959504'
}
varName = 'ptest'
while True:
# GET (the next section of code can be reformatted as one line,but is separated to show the process of parsing)
text = urequests.get(url+varName,headers=headers).text
#print(text)
json = ujson.loads(text)
#print(json)
rows = json.get('rows')
#print(rows)
value = rows[0][varName]
print(value)
*this code is receiving from the "thing" CEEO_Summer and the "property" ptest
How to control LED lights through thingworx: (Get function)
import machine
# Info
url = 'http://pp-1804271345f2.portal.ptc.io:8080/Thingworx/Things/CEEO_Summer/Properties/'
headers = {
'Content-Type':'application/json',
'Accept':'application/json',
'appKey':'f76e9513-0bbc-4b33-af7f-09e5ea959504'
}
varName = 'ptest'
while True:
# GET (the next section of code can be reformatted as one line,but is separated to show the process of parsing)
text = urequests.get(url+varName,headers=headers).text
#print(text)
json = ujson.loads(text)
#print(json)
rows = json.get('rows')
#print(rows)
value = rows[0][varName]
print(value)
pin12 = machine.Pin(12, machine.Pin.OUT)
if value == "0":
pin12.value(1)
else:
pin12.value(0)