Example #1
0
streams.serial()
wifi_driver.auto_init()

print('connecting to wifi...')
# place here your wifi configuration
wifi.link("JoeyCat", wifi.WIFI_WPA2, "joeylovesfood")

pkey, clicert = helpers.load_key_cert('private.pem.key', 'certificate.pem.crt')
thing_conf = helpers.load_thing_conf()
publish_period = 1000  #decreased from 5 secs to one sec

# create aws iot thing instance, connect to mqtt broker, set shadow update callback and start mqtt reception loop
thing = iot.Thing(thing_conf['endpoint'],
                  thing_conf['mqttid'],
                  clicert,
                  pkey,
                  thingname=thing_conf['thingname'])
print('connecting to mqtt broker...')
thing.mqtt.connect()
thing.on_shadow_request(shadow_callback)
thing.mqtt.loop()
thing.update_shadow({'publish_period': publish_period})


#while True:
def pressed():
    print('publish random sample...')
    thing.mqtt.publish(
        "dev/sample",
        json.dumps({
Example #2
0
for _ in range(3):
    try:
        print("> Establishing Link...")
        wifi.link(config.config['SSID'], wifi.WIFI_WPA2, config.config['PSW'])
        break
    except Exception as e:
        print("> ooops, something wrong while linking :(")
else:
    mcu.reset()
print("> linked!")

tx_mutex = threading.Lock()
endpoint, thingname, clicert, pkey = default_credentials.load()
mqtt_id = ''.join(['%02x' % byte
                   for byte in mcu.uid()])  # derive unique id from mcu uid
thing = iot.Thing(endpoint, mqtt_id, clicert, pkey, thingname=thingname)

print("> connecting to mqtt broker...")
thing.mqtt.connect()
print("> connected")
thing.mqtt.loop()

sensor = bme280.BME280(I2C2)
capsense.init()
capsense.on_btn(ethereum_store)
capsense.on_btn(ethereum_store, event=capsense.BTN1_RISE)

config.led_start_publish()
while True:
    tx_mutex.acquire()
    print("> publish temperature and humidity")
Example #3
0
from wireless import wifi
from espressif.esp32net import esp32wifi as wifi_driver
from bosch.bme280 import bme280
from aws.iot import iot, default_credentials
wifi_driver.auto_init()
wifi.link("SSID", wifi.WIFI_WPA2, "PSW")

endpoint, mqttid, clicert, pkey = default_credentials.load()
thing = iot.Thing(endpoint, mqttid, clicert, pkey)
thing.mqtt.connect()
thing.mqtt.loop()
sensor = bme280.BME280(I2C0)
while True:
    thing.mqtt.publish("sensors", {'temp': sensor.get_temp()})
    sleep(1000)
Example #4
0
# place here your wifi configuration
wifi.link("SSID", wifi.WIFI_WPA2, "PSW")

pkey, clicert = helpers.load_key_cert('private.pem.key', 'certificate.pem.crt')
thing_conf = helpers.load_thing_conf()
publish_period = 1000

# discover Greengrass core info
info = gg.discover(thing_conf['endpoint'], thing_conf['thingname'], clicert,
                   pkey)

# N.B. for this example to work it is required that single element connectivity and CA lists are retrieved by discover!
gg_endpoint = info.connectivity()[0]
print('discovered:', gg_endpoint)

# create aws iot thing instance and connect to discovered mqtt broker specifying retrieved CA certificate
thing = iot.Thing(gg_endpoint,
                  thing_conf['mqttid'],
                  clicert,
                  pkey,
                  thingname=thing_conf['thingname'],
                  cacert=info.CA())
print('connecting to mqtt broker...')
thing.mqtt.connect()
thing.mqtt.loop()

while True:
    print('publish random sample...')
    thing.mqtt.publish("dev/sample", json.dumps({'asample': random(0, 10)}))
    sleep(publish_period)