time.sleep(0.2) pycom.rgbled(0xBBBBBB) time.sleep(0.2) pycom.rgbled(0x999999) time.sleep(0.2) pycom.rgbled(0x777777) time.sleep(0.2) pycom.rgbled(0x555555) time.sleep(0.2) pycom.rgbled(0x333333) time.sleep(0.2) pycom.rgbled(0x111111) time.sleep(0.2) # going to sleep py.go_to_sleep() # ============================================================================== # settings deep sleep mode py.setup_int_pin_wake_up(True) py.setup_int_wake_up(True, True) py.setup_sleep(60 * 30) # deep sleep for 2 minutes # enable sensor to wake up acc = LIS2HH12() acc.enable_activity_interrupt(500, 200) # Send data and go to deep sleep _thread.start_new_thread(mainTread, ())
lora.remove_channel(i) # cria uma socket para LoRa s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) # definir a LoRaWAN com o data rate anteriormente estabelecido s.setsockopt(socket.SOL_LORA, socket.SO_DR, SF) # definir o socket como non-blocking s.setblocking(False) time.sleep(5.0) while (True): t_ambient = si.temperature() humidity = si.humidity() pkt = b'PKT #' + int((t_ambient - 7) * 100).to_bytes( 2, 'little') + int(humidity * 100).to_bytes(2, 'little') print('Sending:', pkt) #socket envia a mensagem criada s.send(pkt) time.sleep(5) pycom.heartbeat(True) pycom.heartbeat(False) # coloca o módulo em modo deepsleep py.setup_sleep(7200) py.go_to_sleep() pycom.heartbeat(True) pycom.heartbeat(False) pycom.rgbled(0x007f00)
# enable activity and also inactivity interrupts, using the default callback handler py.setup_int_wake_up(True, True) acc = LIS2HH12() mp = MPL3115A2( py, mode=ALTITUDE ) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals mpp = MPL3115A2( py, mode=PRESSURE ) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters si = SI7006A20(py) lt = LTR329ALS01(py) # enable the activity/inactivity interrupts # set the acceleration threshold to 2000mG (2G) and the min duration to 200ms acc.enable_activity_interrupt(2000, 200) # check if we were awaken due to activity if acc.activity(): pycom.rgbled(0xFF0000) logRun(acc, mp, mpp, si, lt) else: pycom.rgbled(0x00FF00) # timer wake-up time.sleep(0.1) # go to sleep for 1 hour maximum if no accelerometer interrupt happens py.setup_sleep(3600) py.go_to_sleep() ################################################################################ # print("Light (channel Blue lux, channel Red lux): " + str(lt.light()))
from lora import LORA from config import dev_eui, app_eui, app_key from time import sleep from pysense import Pysense from machine import ADC # Formula is calculated using calibration fluids def magicFormula(val): return 20.2489 - (0.00452489 * val) try: adc = ADC() pin = adc.channel(pin='P13', attn=ADC.ATTN_11DB) except Exception: pass # Connect to LoRaWAN n = LORA() n.connect(dev_eui, app_eui, app_key) # Send value val = pin() tmp = "%.2f" % magicFormula(val) n.send(tmp) py = Pysense() py.setup_sleep(1200) # 20 min py.go_to_sleep()
client = TtnClient(config.app_eui, config.app_key, WAIT_FOR_LORA_S, debug=DEBUG) if DEBUG: pycom.rgbled(BLUE) print("Sending payload...") payload = payload_encoder.encode(battery, temperature, humidity, pressure).to_bytes(5, 'big', False) counter = pycom.nvs_get('counter') if counter is None or counter > 65535: counter = 0 datarate = select_datarate(counter) pycom.nvs_set('counter', counter + 1) client.send(payload, datarate) if DEBUG: pycom.rgbled(GREEN) print("Going to sleep...") py.setup_sleep(SLEEP_TIMEOUT_S) py.go_to_sleep(gps=False) if DEBUG: pycom.rgbled(RED) print("This message should not be displayed") except Exception as ex: print("!!! Exception detected !!!", type(ex), ex) finally: if DEBUG: print("Trigger reset") sleep(1) machine.reset()
mp = MPL3115A2( py, mode=ALTITUDE ) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals print("MPL3115A2 temperature: " + str(mp.temperature())) print("Altitude: " + str(mp.altitude())) mpp = MPL3115A2( py, mode=PRESSURE ) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters print("Pressure: " + str(mpp.pressure())) si = SI7006A20(py) print("Temperature: " + str(si.temperature()) + " deg C and Relative Humidity: " + str(si.humidity()) + " %RH") print("Dew point: " + str(si.dew_point()) + " deg C") t_ambient = 24.4 print("Humidity Ambient for " + str(t_ambient) + " deg C is " + str(si.humid_ambient(t_ambient)) + "%RH") lt = LTR329ALS01(py) print("Light (channel Blue lux, channel Red lux): " + str(lt.light())) li = LIS2HH12(py) print("Acceleration: " + str(li.acceleration())) print("Roll: " + str(li.roll())) print("Pitch: " + str(li.pitch())) print("Battery voltage: " + str(py.read_battery_voltage())) time.sleep(3) py.setup_sleep(10) py.go_to_sleep()
pycom.rgbled(color_red) sigfox_network.send(bytes([protocol_version, now_temperature])) pycom.rgbled(color_black) this_interval = 0 already_sent = 1 old_temperature = now_temperature if already_sent == 0: # only end if not already red status if (intervals == 1.0) or (send_all_data == 1): if low_power_consumption_mode == 0: print("sending... (green:%s;v:%s)" % (now_temperature, protocol_version)) pycom.rgbled(0x007f00) sigfox_network.send(bytes([protocol_version, now_temperature])) #pybytes.send_virtual_pin_value(False,15,int(now_temperature)) this_interval = 0 pycom.rgbled(color_black) wdt.feed() if low_power_consumption_mode == 0: time.sleep(measurement_interval) else: py.setup_sleep(measurement_interval) py.go_to_sleep() init_count = 1 sigfox_network.close()
print('\n\n** Humidity and Temperature Sensor (SI7006A20)') print('Humidity', si.humidity()) print('Temperature', si.temperature()) lpp.add_relative_humidity(1, si.humidity()) lpp.add_temperature(1, si.temperature()) mpPress = MPL3115A2(py,mode=PRESSURE) print('\n\n** Barometric Pressure Sensor with Altimeter (MPL3115A2)') print('Pressure (hPa)', mpPress.pressure()/100) lpp.add_barometric_pressure(1, mpPress.pressure()/100) mpAlt = MPL3115A2(py,mode=ALTITUDE) print('Altitude', mpAlt.altitude()) print('Temperature', mpAlt.temperature()) lpp.add_gps(1, 0, 0, mpAlt.altitude()) lpp.add_temperature(2, mpAlt.temperature()) print('Sending data (uplink)...') s.send(bytes(lpp.get_buffer())) s.setblocking(False) data = s.recv(64) print('Received data (downlink)', data) except: 1 lora.nvram_save() py.setup_sleep(300) py.go_to_sleep()
sys.exit() # initialize light sensor # 1X gain is 1lux to 64k lux range. Measurement over 500ms with samples every 100ms lt = LTR329ALS01(py, gain=LTR329ALS01.ALS_GAIN_1X, integration=LTR329ALS01.ALS_INT_100, rate=LTR329ALS01.ALS_RATE_500) time.sleep(0.5) # give time to sensor init # light() returns blue & red wavelength lux values as tuple if lt.light() > (lux_threshold, lux_threshold): pycom.rgbled(0xFF0000) # blink red time.sleep(3) pycom.rgbled(0x000000) # Connect to MQTT gateway and publish luxValue (blue wavelength only) mqtt_msg = {'clientId': client_id, 'luxValue': lt.light()[0]} client = MQTTClient(publish_key + "/" + subscribe_key + "/" + client_id, mqtt_server, port=mqtt_port) client.connect() client.publish(topic=channel_name, msg=json.dumps(mqtt_msg)) client.disconnect() # Set board to deep sleep to save energy, wifi will be disconnected # With measurement periods roughly above 10 sec, wifi disconnect/reconnect is more efficient # than always-on wifi in idle mode py.setup_sleep(meas_frequency) py.go_to_sleep()
s.setblocking(True) # configure it as uplink only s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False) print("MPL3115A2 temperature: " + str(mp.temperature())) print("Altitude: " + str(mp.altitude())) mpp = MPL3115A2( py, mode=PRESSURE ) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters print("Pressure: " + str(mpp.pressure())) print("Temperature: " + str(si.temperature()) + " deg C and Relative Humidity: " + str(si.humidity()) + " %RH") print("Dew point: " + str(si.dew_point()) + " deg C") t_ambient = 24.4 print("Humidity Ambient for " + str(t_ambient) + " deg C is " + str(si.humid_ambient(t_ambient)) + "%RH") print("Light (channel Blue lux, channel Red lux): " + str(lt.light())) print("Acceleration: " + str(li.acceleration())) print("Roll: " + str(li.roll())) print("Pitch: " + str(li.pitch())) print("Battery voltage: " + str(py.read_battery_voltage())) sendPacket = struct.pack('f', si.temperature()) # s.send(bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])) s.send(sendPacket) py.setup_sleep(600) py.go_to_sleep(False)