Exemplo n.º 1
0
def callback(p):
    global active
    if not active:
        ds_pin2.irq(trigger=Pin.IRQ_FALLING, handler=None)
        active = True
        print(active)
        print("Switch activated!")
        do_connect()
        hue_show()
        active = False
        #ds_pin2.irq(trigger=Pin.IRQ_FALLING, handler=callback)
    else:
        print(active)
Exemplo n.º 2
0
def callback(p):
    global active
    if not active:
        do_connect()

        active = True
        print(active)
        print("Switch activated!")
        time.sleep(1)
        active = False

        hue_show()
    else:
        print(active)
Exemplo n.º 3
0
def send_batch(value, volt):
    # send sensor values if batch completed

    wlan = do_connect()
    #wlan=open("wlan.txt").read()[:-1].split(",")
    #print(wlan)
    rtc = machine.RTC()
    if wlan:
        # send them to prometheus
        _send_to_prometheus([wlan[2]],
                            "weather",
                            "temperature",
                            value[0],
                            dimensions={},
                            time=rtc.datetime())
        _send_to_prometheus([wlan[2]],
                            "weather",
                            "air_pressure",
                            value[1],
                            time=rtc.datetime(),
                            dimensions={})
        _send_to_prometheus([wlan[2]],
                            "weather",
                            "humidity",
                            value[2],
                            dimensions={},
                            time=rtc.datetime())
        _send_to_prometheus([wlan[2]],
                            "weather",
                            "volt",
                            volt,
                            dimensions={},
                            time=rtc.datetime())
Exemplo n.º 4
0
    def __init__(self):
        wlan.do_connect()
        self.rtc = machine.RTC()

        try:
            ntptime.settime()
        except:
            pass
            #Use old time

        self.unit = 'F'
        self.hysterisis = 0.5
        self.temp = 0.0
        self.target = 0.0
        self.tempDevice = tempreader.tempreader(self.unit)

        self.m = MQTTReader(mqtthost.MQTT_CLIENT_ID, mqtthost.MQTT_HOST,
                            mqtthost.MQTT_PORT, mqtthost.MQTT_TOPIC)

        self.txt = textout.textout()
Exemplo n.º 5
0
    def __init__(self):

        if hasattr(config, 'DEVICE_ID'):
            self.device_id = config.DEVICE_ID
        else:
            self.device_id = 'mp-' + str(esp.flash_id())

        if hasattr(config, 'SEND_INTERVAL_SECONDS'):
            self.sendIntervalSeconds = config.SEND_INTERVAL_SECONDS
        else:
            self.sendIntervalSeconds = DEFAULT_SEND_INTERVAL_SECONDS

        try:
            from display import Display
            self.display = Display()
        except ImportError:
            self.display = None

        try:
            from sht30 import SHT30
            self.sensor = SHT30()
        except ImportError:
            self.sensor = None

        try:
            from moisture import SoilMoistureSensor
            self.soilMoistureSensor = SoilMoistureSensor()
        except ImportError:
            self.soilMoistureSensor = None

        try:
            from mhz19 import MHZ19
            self.mhz19 = MHZ19()
            self.mhz19.start()
        except ImportError:
            self.mhz19 = None

        disable_access_point()
        do_connect(WLAN_SSID, WLAN_PASSWORD)

        self.ntptimeWhenZero = 0
Exemplo n.º 6
0
import network
from machine import Pin
import time
import json
import urequests
from wlan import do_connect

do_connect()

button = Pin(4, Pin.IN, Pin.PULL_UP)

start = time.ticks_ms()

apiKey = 'XXXXXXXXXXXXXXXXXXXXXXXX'  #reemplazar por la propia API KEY

url = "https://api.pushbullet.com/v2/pushes"
headers = {'Access-Token': apiKey, 'Content-Type': 'application/json'}

data = {
    'type': 'note',
    'body': 'Mensaje desde MicroPython',
    'title': 'MicroPython'
}
dataJSON = json.dumps(data)

while True:
    if (button.value() == 0):
        delta = time.ticks_diff(time.ticks_ms(), start)
        if (delta > 5000):
            print("Enviando mensaje")
            r = urequests.post(url, headers=headers, data=dataJSON)
Exemplo n.º 7
0
# Complete project details at https://RandomNerdTutorials.com

import textout
import time
import machine
import ntptime
import wlan

#ntptime.settime()

wlan.do_connect()
rtc = machine.RTC()
#rtc.init((2014, 5, 1, 4, 13, 0, 0, 0))
print(rtc.datetime())
t = textout.textout()
while True:
    date_str = "Date: {1:02d}/{2:02d}/{0:4d}".format(*rtc.datetime())
    time_str = "UTC: {4:02d}:{5:02d}:{6:02d}".format(*rtc.datetime())
    t.text(time_str)
    time.sleep_ms(100)
Exemplo n.º 8
0
import network
from config import WLAN_SSID, WLAN_PASSWORD
from wlan import do_connect, print_status

print_status('Station', network.WLAN(network.STA_IF))
print_status('Access Point', network.WLAN(network.AP_IF))

do_connect(WLAN_SSID, WLAN_PASSWORD)
Exemplo n.º 9
0
from wlan import do_connect
do_connect('my wifi', 'simsalabim')

from enc_oscclient import main
main()
Exemplo n.º 10
0
from wlan import do_connect

do_connect("my wifi", "simsalabim")

from enc_oscclient import main

main()