FrontPage
command: set readInterval=60000
command: set execInterval=0
command: set reportLength=240
command: program Sensors
program: '
program: ' init i2c
program: ex("pi4j", "i2c use 1")
program: '
program: ' init lux sensor
program: ex("pi4j", "i2c write1 0x29,0x80,0x03") 'power up the tsl2561 lux sensor
program: ex("pi4j", "i2c write1 0x29,0x81,0x00")
program: ex("pi4j", "i2c write1 0x29,0x86,0x00") 'scale
program: ex("pi4j", "i2c write1 0x29,0x80,0x00") 'power down
program: ex("pi4j", "i2c write1 0x29,0x80,0x03") ' power up again
program: delay(50)
program: '
program: 'get the lux value
program: v1=ex("pi4j", "i2c read1 0x29,0x8c")
program: v2=ex("pi4j", "i2c read1 0x29,0x8d")
program: lux=s2i(v2)*256+s2i(v1)
program: '
program: 'get the Aanalog value from the ADS1115 ch0
# // Start with default values
# uint16_t config
# = ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val)
# ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
# ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
# ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
# ADS1015_REG_CONFIG_DR_1600SPS | // 1600 samples per second (default)
# ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
#
program: config=0x0003|0x0000|0x0000|0x0000|0x0080|0x0100
#
# // Set PGA/voltage range
# config |= m_gain;
program: config=config|0x0000
#
# // Set single-ended input channel
# switch (channel)
# {
# case (0):
# config |= ADS1015_REG_CONFIG_MUX_SINGLE_0; //SINGLE_1, SINGLE_2, SINGLE_3
# break;
#program: config=config|0x4000 'channel 0
program: config= config|0x5000 'channel 1
#
# // Set 'start single-conversion' bit
# config |= ADS1015_REG_CONFIG_OS_SINGLE;
program: config=config|0x8000
#
# writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
#
program: ex("pi4j", "i2c write2 0x49,0x01,"+config)
#
# // Wait for the conversion to complete
# delay(m_conversionDelay);
#
program: delay(10)
#
# // Read the conversion results
# // Shift 12-bit results right 4 bits for the ADS1015
# return readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
#
program: v2=ex("pi4j","i2c read2 0x49,0x00")
program: airpol=s2i(v2)
#program: airpol=(airpol+32768)/16
program: airpol=airpol+800
program: '
program: ' get temperature
program: v1=ex("pi4j", "i2c read1 0x48,0x00")
program: tmp=s2i(v1)
program: '
program: ' get motion
program: v1=ex("pi4j","get-a-0")
program: motion=s2i(v1)
program: '
program: ex("pi4j", "i2c close")
program: '
program: date=ex("service","getCurrentDate.")
program: ex("service","putSendBuffer device=light, Date="+date+", v="+lux)
program: ex("service","putSendBuffer device=airPol, Date="+date+", v="+airpol)
program: ex("service","putSendBuffer device=temp, Date="+date+", v="+tmp)
program: ex("service","putSendBuffer device=motion, Date="+date+", v="+motion)
program: ex("service","sendResults.")
command: end Sensors
command: run Sensors
command: set pageName="sensors-1-h-<hour>"