Beispiel #1
0
    def start(self, group):
        if not self.is_on:
            raise RuntimeError('Start Wifi before this method')

        try:
            # Intialize ESP-NOW and resiger coallback function.
            espnow.init()
            espnow.add_peer(StuduinoBitRadio.BROADCAST_MAC_ADDRESS)
            espnow.on_recv(self.__recv_cb)
        except OSError as e:
            print(e)

        self.__group = group
Beispiel #2
0
from machine import ADC, Pin
import network
from esp import espnow
import time

w = network.WLAN()
w.active(True)

light = ADC(Pin(34))
light.atten(ADC.ATTN_11DB)
light.width(ADC.WIDTH_12BIT)

BROADCAST = b'\xFF' * 6

espnow.init()
espnow.add_peer(BROADCAST)

while True:
    lumen = light.read()
    # 1 = go, 0 = stop
    if (lumen > 20):
        status = 1
    else:
        status = 0
    righthand = {"direction" : status}
    print("Light: ", lumen)
    print("Check: ", str(righthand))
    espnow.send(BROADCAST, str(righthand))
    time.sleep(0.5)
Beispiel #3
0
def init_wifi():
    w = network.WLAN()
    w.active(True)
    espnow.init()
    espnow.add_peer(BROADCAST)
Beispiel #4
0
# config OLED
i2c = I2C(-1, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
# config network
w = network.WLAN()
w.active(True)
print('my mac addr (Player):',
      ubinascii.hexlify(w.config('mac'), ':').decode())

# config esp32
UNICAST_CONTROLLER = b'\x30\xae\xa4\x12\x1f\x28'
# UNICAST_CONTROLLER = b'\x30aea4121f28'
espnow.init()
espnow.add_peer(UNICAST_CONTROLLER)


def setterOLED(*messenger, posy=[]):
    if (not posy):
        posy = [0, 10, 20]

    oled.fill(0)
    for msg in messenger:
        print(msg)
        oled.text(str(msg), 0, posy.pop(0))
    oled.show()


def addLightOnBorad(color):
    print('sw color :' + color)
def connectDevice(device):
    espnow.add_peer(MAC[device])
    mac = MAC[device]
    while (signal[device] == False):  # bug on staging
        espnow.send(mac, 'connecting')
        time.sleep(1)