Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more.
0

Json for domoticz
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Json for domoticz

by samourai47 on Thu Feb 27, 2020 4:17 am

Hello. Sorrye for my poor english and my little level

I installed cirucitpython for use with a tsl2561 composant. All is ok and i have good results.
I want update a dummy device in domoticz with the value of "Brodband" for example
The code i use
Code: Select all | TOGGLE FULL SIZE
import board
import busio
import adafruit_tsl2561
import urllib

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
# Create the TSL2561 instance, passing in the I2C bus
tsl = adafruit_tsl2561.TSL2561(i2c)
# Print chip info
print("Chip ID = {}".format(tsl.chip_id))
print("Enabled = {}".format(tsl.enabled))
print("Gain = {}".format(tsl.gain))
print("Integration time = {}".format(tsl.integration_time))
print("Configuring TSL2561...")
# Enable the light sensor
tsl.enabled = True
# Set gain 0=1x, 1=16x
tsl.gain = 0
# Set integration time (0=13.7ms, 1=101ms, 2=402ms, or 3=manual) tsl.integration_time = 1
print("Getting readings...")
# Get raw (luminosity) readings individually
broadband = tsl.broadband
infrared = tsl.infrared
# Get raw (luminosity) readings using tuple unpacking
#broadband, infrared = tsl.luminosity
# Get computed lux value
lux = tsl.lux
# Print results
print("Enabled = {}".format(tsl.enabled))
print("Gain = {}".format(tsl.gain))
print("Integration time = {}".format(tsl.integration_time))
print("Broadband = {}".format(broadband))
print("Infrared = {}".format(infrared))
print("Lux = {}".format(lux))
httpresponse = urllib.urlopen('http://192.168.0.120:8080/json.htm?type=command&param=udevice&idx=45&nvalue=0&svalue='+str(broadband)'')
tsl.enabled = False


I had 2 lines with the original code
import urllib
httpresponse = urllib.urlopen('http://192.168.0.120:8080/json.htm?type=command&param=udevice&idx=45&nvalue=0&svalue='+str(broadband)'')
But it dosent' work.....
-> SyntaxError: invalid syntax

I use this line in an another python script and it's ok

Can you help me writing this line correctly in circuitpython
Thank you

samourai47
 
Posts: 1
Joined: Thu Feb 27, 2020 4:00 am

Re: Json for domoticz

by tannewt on Mon Mar 02, 2020 8:28 pm

Hi! What board are you running this on? CircuitPython itself doesn't have urllib but CPython and Blinka on Raspberry Pi would.

tannewt
 
Posts: 1536
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.