Esempio n. 1
0
def main():
    oled = OLED()
    oled.write_lines(line1='start...')
    currdir = uos.getcwd()
    try:
        fconfig = open(currdir + 'config.ini', 'r')
        configdic = ujson.loads(fconfig.read())
        fconfig.close()
    except:
        configdic = {'WiFiName': '', 'WiFiPasswd': False}
        fconfig = open(currdir + 'config.ini', 'w')
        fconfig.write(ujson.dumps(configdic))
        fconfig.flush()
        fconfig.close()

    if configdic['WiFiPasswd']:
        oled.write_lines(line2='connecting to network...')
        flag, wifi_status, esp8266_ip = connect_wifi(configdic['WiFiName'],
                                                     configdic['WiFiPasswd'])
        if flag:
            oled.write_lines(line1='ip:' + esp8266_ip, line2='', line3='')
        else:
            oled.write_lines(line3='connect network failed, restarting...')
            configdic = {'WiFiName': '', 'WiFiPasswd': False}
            fconfig = open(currdir + 'config.ini', 'w')
            fconfig.write(ujson.dumps(configdic))
            fconfig.flush()
            fconfig.close()
            machine.reset()
    else:
        esp8266_ip = apmode(wifi_name, wifi_password)
        oled.write_lines(line1='wifi:' + wifi_name,
                         line2='pswd:' + wifi_password,
                         line3='ip  :' + esp8266_ip)
        webserver()

    # autosynctime()

    BROADCAST_IP = esp8266_ip[:esp8266_ip.rfind('.')] + '.255'
    mq = mqtt(oled=oled,
              client_id=client_id,
              username=product_id,
              password=authinfo,
              macs=macs,
              BROADCAST_IP=BROADCAST_IP,
              BROADCAST_PORT=BROADCAST_PORT)
    while True:
        mq.connect()
        time.sleep(30)
Esempio n. 2
0
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
import uos, machine
#uos.dupterm(None, 1) # disable REPL on UART(0)
import gc
#import webrepl
#webrepl.start()
gc.collect()

import wifi

a=wifi.connect_wifi()
if a==False:
    wifi.html_sever()


print("wifi connect done")






Esempio n. 3
0
from time import sleep
from linear_fan_control import LinearFanControl
from temp_reader import TempReader
from rpm_reader import RPMReader
from wifi import connect_wifi
from metrics import send_metrics
from machine import Pin

connect_wifi()

lfc_in = LinearFanControl(pwm_pin=23, min_temp=23, max_temp=30)
lfc_out = LinearFanControl(pwm_pin=18, min_temp=23, max_temp=30)

rpm_in = RPMReader(rpm_pin=22)
rpm_out = RPMReader(rpm_pin=5)

temp_reader = TempReader(pin=19)
# temp_reader_2 = TempReader(pin=16)
fan_switch = Pin(21, Pin.OUT)
fan_switch_2 = Pin(17, Pin.OUT)

while True:
    temp = 100
    temp2 = 100
    try:
        temps = list(temp_reader.read_temps())
        temp = temps[0]
        temp2 = temps[1]
    except Exception:
        pass
import machine as m
from neopixel import NeoPixel
from time import sleep
import math
from color import hsl2rgb
from microWebSrv import MicroWebSrv  # download at https://github.com/jczic/MicroWebSrv
import gc
import _thread

# edit the networks.py file or use your own code here to connect to your wifi
from wifi import connect_wifi

wifi = connect_wifi()

r = m.reset  # shortcut

NEOPIXEL_PIN = 12
PIXELCOUNT = 16

SPEED = 0.02
SCALER = 40

np = NeoPixel(m.Pin(NEOPIXEL_PIN), PIXELCOUNT, timing=True)

max_lum = 20
hue = 50


def clear():
    """ clear all pixels to black """
    for i in range(PIXELCOUNT):
Esempio n. 5
0
import wifi

wifi.connect_wifi()

Esempio n. 6
0
def main():
    # look-up color dict - api 'field1' is used as the key:
    colors = {
        'red': (255, 0, 0),
        'orange': (211, 84, 0),
        'yellow': (254, 183, 12),
        'green': (0, 128, 0),
        'cyan': (0, 255, 255),
        'blue': (0, 0, 255),
        'purple': (128, 0, 128),
        'magenta': (255, 0, 255),
        'pink': (254, 52, 62),
        'white': (255, 255, 230),
        'oldlace': (255, 200, 130),
        'warmwhite': (255, 200, 130),
        # 'red':          (255, 0, 0),
        # 'orange':       (255, 30, 0),
        # 'yellow':       (255, 110, 1),
        # 'green':        (0, 255, 0),
        # 'cyan':         (0, 255, 255),
        # 'blue':         (0, 0, 255),
        # 'purple':       (128, 0, 128),
        # 'magenta':      (255, 0, 50),
        # 'pink':         (255, 40, 50),
        # 'white':        (255, 255, 170),
        # 'oldlace':      (255, 150, 50),
        # 'warmwhite':    (255, 150, 50)
    }

    host = 'https://thingspeak.com/'
    topic = 'channels/1417/feeds/last.json'
    api = host + topic

    neopixels = []  # holder for the neo pixels
    pixel_pins = [0]  # D3
    num_pixels = 1  # leds per strip

    # define pins, create neopixel objects, and populate neopixels list:
    for i in range(len(pixel_pins)):
        pin = Pin(pixel_pins[i], Pin.OUT)
        neopixels.append(neopixel.NeoPixel(pin, num_pixels))

    # turn off any lit neopixels:
    neopixel_blank(neopixels)

    # seed the random generator
    adc = ADC(0)
    seed = adc.read()
    print("random seed: ", seed)
    urandom.seed(seed)

    # attempt to connect to wifi,
    # if connected, break from while loop:
    while True:
        # keep trying to connect to the internet:
        try:
            wifi.connect_wifi()
            break
        except Exception:
            print("Can not connect to wifi")
            time.sleep(5)

    prev_color = ''
    previous_rgb = (0, 0, 0)
    recvd_color = ''
    target_rgb = (0, 0, 0)

    count = 0
    interval = 20  # seconds delay between updates
    last_update = time.time() - interval
    # last_update = -100 # time.time() + interval

    # main loop:
    while True:
        if time.time() > last_update + interval:
            recvd_color = api_request(api)
            last_update = time.time()

            # If cheerlights color feed has not changed, increment counter:
            if recvd_color == prev_color:
                count += 1

            # if color has changed, reset counter, re-assign prev_color,
            # extract rgb color from color lookup dict:
            else:
                count = 1
                prev_color = recvd_color
                target_rgb = new_neopixel_color(recvd_color, colors)

            print(str(count) + ': ' + recvd_color)

        previous_rgb = color_transition(neopixels, previous_rgb, target_rgb)