def SendToBlynk(blynk_auth, result): # from time import sleep # import urequests # blynk_host = 'https://blynk-cloud.com' # for i, value in enumerate(result): # res = urequests.put(url='%s/%s/update/V%d' % (blynk_host, blynk_auth, i), json=['%s' % value]) # if res.status_code != 200: # print('Error updating pin V%d: %d %s' % (i, res.status_code, res.text)) # else: # print('Updated pin V%d' % i) # del res # sleep(0.25) # print('Data written to Blynk') from time import sleep import sys, gc import blynklib_mp blynk = blynklib_mp.Blynk(blynk_auth) CONNECT_PRINT_MSG = '[CONNECT_EVENT]' DISCONNECT_PRINT_MSG = '[DISCONNECT_EVENT]' @blynk.handle_event("connect") def connect_handler(): print(CONNECT_PRINT_MSG) print('Sleeping 1 sec in connect handler...') sleep(1) for i, value in enumerate(result): print('Writing pin V%d' % i) blynk.virtual_write(i, value) blynk.disconnect() @blynk.handle_event("disconnect") def connect_handler(): print(DISCONNECT_PRINT_MSG) print('Sleeping 1 sec in disconnect handler...') sleep(1) blynk.run() del blynk del sys.modules['blynklib_mp'] gc.collect()
print('go to deep sleep until next measure ', sleep_sec_measure) go_to_deepsleep(sleep_sec_measure) # end app ############################ # main ############################ # project meaudre, cloud server # public blynk server init_RTC([1, 1, 0, 0, 0]) blynk = blynklib.Blynk('128bf199aa8744f88a586beecb6b64d9') print('BLYNK: blynk on public server created: ', type(blynk)) first_connect = True update_done = 0 # global. set to 1 if OK or -1 if error in blynk connect call back temp_haut = 0.0 temp_milieu = 0.0 ######################################################## # i2c and oled init # run before wifi and blynk, to provide feedbaks ######################################################## #https://github.com/micropython/micropython/tree/master/drivers/display #There are two hardware I2C peripherals with identifiers 0 and 1. Any available output-capable pins can be used for SCL and SDA but the defaults are given below.
ir_transmitter = IRTransmitter(Pin(TRANSMITTER_PIN)) wlan = network.WLAN(network.STA_IF) spi = SPI(sck=Pin(TinyPICO.DOTSTAR_CLK), mosi=Pin(TinyPICO.DOTSTAR_DATA), miso=Pin(TinyPICO.SPI_MISO)) dotstar = DotStar(spi, 1, brightness=0.0) dotstar[0] = (0, 188, 255, 0.5) TinyPICO.set_dotstar_power(True) syncing = True ac_on = None button_cooldown_time = 0 connect() blynk = blynklib.Blynk(secret.BLYNK_AUTH, log=print) @blynk.handle_event("write V" + str(BUTTON_VPIN)) def write_handler(pin, value): global ac_on if ac_on is None: ac_on = True if int(value[0]) == 1 else False return if int(value[0]) == 1 and not ac_on: ir_transmitter.play(ir_code.POWER_ON) elif int(value[0]) == 0 and ac_on: ir_transmitter.play(ir_code.POWER_OFF)
WIFI_SSID = 'YourWifiSSID' WIFI_PASS = '******' BLYNK_AUTH = 'YourAuthToken' GPIO_DHT22_PIN = 4 print("Connecting to WiFi network '{}'".format(WIFI_SSID)) wifi = network.WLAN(network.STA_IF) wifi.active(True) wifi.connect(WIFI_SSID, WIFI_PASS) while not wifi.isconnected(): time.sleep(1) print('WiFi connect retry ...') print('WiFi IP:', wifi.ifconfig()[0]) print("Connecting to Blynk server...") blynk = blynklib.Blynk(BLYNK_AUTH) T_COLOR = '#f5b041' H_COLOR = '#85c1e9' ERR_COLOR = '#444444' T_VPIN = 3 H_VPIN = 4 dht22 = dht.DHT22(Pin(4, Pin.IN, Pin.PULL_UP)) @blynk.handle_event('read V{}'.format(T_VPIN)) def read_handler(vpin): temperature = 0.0 humidity = 0.0
WIFI_SSID = 'Gliwice test 5G 300% mocy' WIFI_PASS = '******' wifi = network.WLAN(network.STA_IF) wifi.active(True) wifi.connect(WIFI_SSID, WIFI_PASS) # check if board connected connect_status = wifi.isconnected() print("Wifi connection result: " + str(connect_status)) connect_to_wifi() CONFIG_PATH = "configuration\\config.json" config = Config(CONFIG_PATH) blynk = blynk.Blynk(config.get_blynk_auth_token()) air_value = 3620 water_value = 1360 minimum_soil_moisture_percentage = 30 moisture_sensor_34 = MoistureSensor(pin_number=34, air_value=air_value, water_value=water_value) moisture_sensor_35 = MoistureSensor(pin_number=35, air_value=air_value, water_value=water_value) moisture_sensor_32 = MoistureSensor(pin_number=32, air_value=air_value,