Exemple #1
0
 def CheckWifi(self):
     """Check if Connected to WiFi. If not, connect."""
     if not self.ssid:
         self._GetDefaults()
     if not (wifiCfg.wlan_sta.isconnected()):
         wifiCfg.doConnect(self.ssid, self.password)
         self.ShowError('WiFi connected')
Exemple #2
0
def Connect():
    try:
        ssid, password = wifiCfg.deviceCfg.wifi_read_from_flash()
    except AttributeError:
        try:
            ssid, password = wifiCfg.wifi_read_from_flash()
        except AttributeError:
            ShowText('no SSID found', error=True)
    if not (wifiCfg.wlan_sta.isconnected()):
        wifiCfg.doConnect(ssid, password)
label2 = M5TextBox(15, 80, "Text", lcd.FONT_DejaVu24,0xAFFFAF, rotate=0) #MQTT sent msg display
label3 = M5TextBox(15, 100, "Sensor: ", lcd.FONT_DejaVu24,0xCFFF9F, rotate=0) #MQTT sent msg display
label_MQTT_R = M5TextBox(15, 120, "RX_Msg:", lcd.FONT_DejaVu24,0xFFF000, rotate=0) #MQTT received msg display
label_cnt = M5TextBox(220, 225, "CNT: ", lcd.FONT_Default,0xFFEEBB, rotate=0)  # run count
label_LCD = M5TextBox(220, 205, "LCD_BK: ", lcd.FONT_Default,0xAAEEAA, rotate=0)
label_cnt_msg = M5TextBox(20, 205, "MQTT CNT: ", lcd.FONT_Default,0xAAEEAA, rotate=0) 
image_B_icon = M5Img(140,220, "res/bnt_B.jpg", True)
#Vb values
label_akku = M5TextBox(20, 225, "Text", lcd.FONT_Default,0xFFFFAA, rotate=0)
adc = machine.ADC(35) 
ratio =2
#------------ADC V akku G35
adc.atten(adc.ATTN_11DB)

m5mqtt.subscribe(str('test_m5stack_zell'), fun_test_m5stack_zell_)
wifiCfg.doConnect('TC', 'sthz@2020')
m5mqtt.start()
label1.setText('Hello M5 MQTT start')
m5mqtt.publish(str('test_m5stack_zell'),str('M5 is now online'))

#----------get time
#rtc = machine.RTC()
#rtc.ntp_sync(server="1.europe.pool.ntp.org", tz="CET-1CEST")
#rtc.ntp_sync(server="hr.pool.ntp.org", tz="CET-1CEST")
#rtc.synced()
#env0 = unit.get(unit.ENV, unit.PORTA)
try:
            env0 = unit.get(unit.ENV, unit.PORTA)
            label3.setText("Sensor: OK")
except:
            label3.setText("N.A. ")
res_tmp = 0
T_intval = 0.1

#-------------MQTT vars
Device_ID = 'ESP32_01'
Alert_msg = 0x400200  # need replacement & over temperature
MQTT_Server = 'st.devmolv.com'  #default connection
MQTT_Server2 = 'iot.eclipse.org'
MQTT_Server3 = 'test.mosquitto.org'
#Topic_ID = 'stsmd/+/+'
Data_ava_flag = 0b1000111

import wifiCfg
#MQTT lib auto did wifi connections
wifiCfg.screenShow()
wifiCfg.doConnect('WH10', 'Zell9090')
#wifiCfg.doConnect('TC', 'sthz@2020')
wifiCfg.autoConnect(lcdShow=True)
wait(0.1)

#m5mqtt = M5mqtt(Device_ID, MQTT_Server2, 1883, '', '', 300)
m5mqtt = M5mqtt(Device_ID, MQTT_Server, 1883, '', '', 3000)
#m5mqtt = M5mqtt('M5_SMD01', 'test.mosquitto.org', 1883, '', '', 300)
wait(0.1)
#global control flags
Alarm_flag = 0
MQTT_data_send_flag = 0
MQTT_Alert_send_flag = 0
run_cnt = 0
Msg_cnt_R = 0
Msg_cnt_T = 0
Exemple #5
0
            choose_circle.setPosition(y=pos_y_start + 4 + pos * 15)
        password.setText(card.keyString)
        time.sleep_ms(10)


wifi_update()
ssid.setText(wifiList[0][0])
link_ssid = wifiList[0][0]

btnB._event |= 0x01

while True:
    if btnA.wasPressed():
        screenShow()
        link_pwd = card.keyString
        if doConnect(link_ssid, link_pwd, True):
            saveWiFi(link_ssid, link_pwd)
            import uiflow
            uiflow.start('flow')
            uiflow.modeSet('internet')
            import machine
            machine.reset()
        else:
            setScreenColor(0x000000)
            show_title()
            label_ssid.show()
            ssid.show()
            rect.show()
            label_pwd.show()
            password.show()
            lcd.font(lcd.FONT_Default)
from m5stack import *
from m5ui import *
from uiflow import *
import wifiCfg
import urequests
import ujson

while True:
    lcd.clear()
    wifiCfg.doConnect('mywifi', 'mypassword')
    req = urequests.get(
        'http://dataservice.accuweather.com/currentconditions/v1/22889?apikey=ZFPeG8rPkVmqvZ8QrAOUNwG4mi334Yul'
    )
    tempi = (ujson.loads((req.text)))[0]["Temperature"]["Metric"]
    time = (ujson.loads((req.text)))[0]["LocalObservationDateTime"]
    condition = (ujson.loads((req.text)))[0]["WeatherText"]
    lcd.print(str(tempi["Value"]), 0, 0)
    lcd.print(str(time), 0, 20)
    lcd.print(str(condition), 0, 40)
    lcd.print(
        '''
      \   /
       .-.
   -- (   ) --
       `-’
      /   \
  ''', 0, 90, 0xffff00)

    req.close()
    wait_ms(1800000)
# Write your code here :-)
Exemple #7
0
import ujson
from m5stack import *
from m5ui import *
import wifiCfg
from m5mqtt import M5mqtt

fichier = open('config.json')
config = ujson.load(fichier)
if not wifiCfg.is_connected():
    lcd.text(10, 10, 'connection au wifi')
    wifiCfg.doConnect(config['ssid'], config['passwd'])

def callback(topic_donnees):
    print((topic_donnees))

m5qtt = M5mqtt("M5stack", "test.mosquitto.org", 1883)
m5qtt.("tuto_topic", callback)

m5qtt.start()

while True:
    pass
Exemple #8
0
rgb.setBrightness(10)  
rgb.setColorAll(0x330033)

# First thing is we need to see/connect to wifi
# Need to figure out where - Nick or Matt
wifiCfg.wlan_sta.active(True)
networks = wifiCfg.wlan_sta.scan()
for ssid, bssid, channel, rssi, authmode, hidden in networks:
  ssid = ssid.decode('utf-8')
  if ssid==altName:
    apName=altName
    apPassword=altPassword
  
if not (wifiCfg.wlan_sta.isconnected()):
  print('Connecting to '+apName)
  wifiCfg.doConnect(apName, apPassword)
  while not (wifiCfg.wlan_sta.isconnected()):
    wait(1)
    print('Waiting to connect')
print('Wifi Connected')

# Get the clock from ntp and set the real time clock
updateTime()
# Turn off all the dots
rgb.setColorAll(0x000000)
# This will turn on the Dots necessary to show current time
turnDotsOn()
hourTicks= 23 - currentHour
# Set up the callback for the button press
btnA.wasPressed(toggleShow)
# Then crank up the time for 1 second intervals
import wifiCfg
from m5stack import *
from m5ui import *
from uiflow import *
import urequests as requests
from time import sleep
import network, machine
setScreenColor(0x111111)

#wifiCfg.autoConnect()
wifiCfg.doConnect('@@@', '@@@')


def gold_price_api():
    gold_price_api = "https://api.thingspeak.com/apps/thinghttp/send_request?api_key=AT8VTTC4BMVYUWRT"
    response = requests.get(gold_price_api).text
    gold_data = response.split(" ")[0]
    label0 = M5TextBox(127, 67, "Gold", lcd.FONT_DejaVu40, 0xffd11a, rotate=90)
    label1 = M5TextBox(75,
                       35,
                       gold_data,
                       lcd.FONT_DejaVu40,
                       0xFFFFFF,
                       rotate=90)
    label2 = M5TextBox(25,
                       75,
                       "usd/oz",
                       lcd.FONT_DejaVu24,
                       0xFFFFFF,
                       rotate=90)
Exemple #10
0
    html = str(html) + str(Faq)
    html = str(html) + str(Footer)
    return html


ip = wifiCfg.wlan_sta.ifconfig()

#create labels to display the information on the M5Stack screen
label1 = M5TextBox(0, 0, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(0, 24, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(0, 60, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(0, 85, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(120, 200, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)

response = None
wifiCfg.doConnect('YourAPsSSID', 'YourAPsPassword')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('192.168.1.30', 80))
s.listen(5)

if wifiCfg.wlan_sta.isconnected():
    label1.setText('wifi connected')
    label2.setText('  Your IP ' + str(ip[0]))
else:
    label1.setText('wifi not connected')
    wait_ms(2)

while True:
    conn, addr = s.accept()
    request = conn.recv(1024)
    request = str(request)
from m5stack import *
from m5ui import *
from uiflow import *
import wifiCfg
import ntptime
import i2c_bus
import unit

setScreenColor(0x222222)
color0 = unit.get(unit.COLOR, unit.PORTA)

distmm = None

wifiCfg.doConnect('Name', 'Password')
label2 = M5TextBox(92, 43, "D", lcd.FONT_DejaVu56, 0xFFFFFF, rotate=0)
time = M5TextBox(34, 152, "00:00:00", lcd.FONT_DejaVu56, 0xFFFFFF, rotate=0)

ntp = ntptime.client(host='de.pool.ntp.org', timezone=1)
speaker.tone(800, 200)
i2c0 = i2c_bus.easyI2C((21, 22), 0x52, freq=4000)
while True:
    i2c0.write_u8(0x52, 0x00)
    distmm = (i2c0.read_data(1, i2c_bus.INT16BE))[-1]
    label2.setText(str((str(distmm) + str('mm'))))
    label0.setText(str(ntp.formatTime(':')))
    wait_ms(2)
Exemple #12
0
screen.clean_screen()
screen.set_screen_bg_color(0x387f98)

x = None
y = None
url = None
output = None
img = None
headers = None
inputs = None
status = None
size = None
neuron = None
runway_set = None

wifiCfg.doConnect('<uuid>', ',password>')
label0 = M5Label('',
                 x=224,
                 y=25,
                 color=0x000,
                 font=FONT_UNICODE_24,
                 parent=None)
label1 = M5Label('text',
                 x=0,
                 y=217,
                 color=0x000,
                 font=FONT_UNICODE_24,
                 parent=None)
label0.set_hidden(True)
if wifiCfg.wlan_sta.isconnected():
    label0.set_text('wifi ok')
Exemple #13
0
#Create labels to display the information on the M5Stack screen
label1 = M5TextBox(0, 0, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(0, 12, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)

redRectangle = M5Rect(0, 0, 320, 240, 0xff0000, 0xFFFFFF)
busylabel = M5TextBox(61, 81, "BUSY", lcd.FONT_DejaVu72, 0xFFFFFF, rotate=0)

rgb.setColorAll(0x000000)
setScreenColor(0x000000)
lcd.setBrightness(0)
redRectangle.hide()
busylabel.hide()

response = None
wifiCfg.doConnect('<<SSID>>', '<<PASSWORD>>')

if wifiCfg.wlan_sta.isconnected():
    label1.setText('wifi connected')
    ip = wifiCfg.wlan_sta.ifconfig()
    label2.setText('Your IP Address is: ' + str(ip[0]))
    wait_ms(2000)
else:
    label1.setText('wifi not connected')
    wait_ms(2000)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ip[0], 80))
s.listen(5)

while True:
Exemple #14
0
led = machine.PWM(machine.Pin(10),5000,99)
esp32.wake_on_ext0(pin = machine.Pin(39, mode = Pin.IN), level = esp32.WAKEUP_ALL_LOW)
lcd.setTextColor(0xaaaaaa, lcd.BLACK)
lcd.font(lcd.FONT_Ubuntu)

def get_moisture():
  i2c = i2c_bus.easyI2C(i2c_bus.PORTA, 0x36)
  i2c.write_u8(0x0f, 0x10)
  wait_ms(5)
  val = i2c.read(2)
  val = ustruct.unpack(">H", val)[0]
  return int(val)

while(True):
  axp.setLDO2Volt(3.3) #turn the screen back on
  while not wifiCfg.doConnect('guest', '12345678', lcdShow=True): pass
  wait(1)
  lcd.clear()

  display.showdata(get_moisture())

  moisture = get_moisture() #get moisture
  try:
    response = urequests.request(
      method='POST',
      url='http://io.adafruit.com/api/v2/dwarrenku/feeds/moisture/data',
      json={'value':moisture},
      headers={'Content-Type':'application/json','X-AIO-Key':'aio_NFup883jK6FQ22XvUHRnJ4kiubT4'}
    )
    if response.status_code == 200:
      led.duty(99)
Exemple #15
0
    global temperature, humidity, ticks
    axp.powerOff()
    pass


btnA.wasPressed(buttonA_wasPressed)


@timerSch.event('timer1')
def ttimer1():
    global temperature, humidity, ticks
    ticks = (ticks if isinstance(ticks, int) else 0) + 1
    pass


wifiCfg.doConnect('YOUR_WIFI_SSID', 'YOUR_WIFI_PASS')
m5mqtt.start()
temperature = '---'
humidity = '---'
ticks = 0
axp.setLDO2Volt(2.8)
setScreenColor(0x000000)
lcd.font(lcd.FONT_DejaVu24)
timerSch.run('timer1', 3500, 0x00)
while True:
    if ticks % 2 == 0:
        lcd.fill(0x000000)
        image0.changeImg("res/temp3.jpg")
        image0.setPosition(8, 8)
        lcd.print(temperature, 8, 80, 0xff6666)
    else:
    pass


btnA.wasPressed(buttonA_wasPressed)


def buttonC_wasPressed():
    lcd.setBrightness(10)
    #  speaker.tone(1000, 20)
    pass


btnC.wasPressed(buttonC_wasPressed)

# connect to your wifi
wifiCfg.doConnect('YOUR SSID', 'YOUR PASSWD')

# retrieve json data from official github of Italian Protezione Civile DPT. Data were updates daily after 17:00
req = urequests.get(
    "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-json/dpc-covid19-ita-regioni-latest.json"
)
while True:

    totpos = (ujson.loads((req.text)))[i]["totale_positivi"]
    time = (ujson.loads((req.text)))[i]["data"]
    nuovipos = (ujson.loads((req.text)))[i]["nuovi_positivi"]
    guariti = (ujson.loads((req.text)))[i]["dimessi_guariti"]
    decessi = (ujson.loads((req.text)))[i]["deceduti"]
    regione = (ujson.loads((req.text)))[i]["denominazione_regione"]

    lcd.clear()
Exemple #17
0
                   rotate=0)
wait_ms(10000)

label6 = M5TextBox(30,
                   10,
                   "XMas Fever control",
                   lcd.FONT_DejaVu24,
                   0xFFFFFF,
                   rotate=0)
label4 = M5TextBox(60, 60, "", lcd.FONT_DejaVu24, 0x00FF00, rotate=0)

#initialize M5Stack NCIR sensor unit
ncir0 = unit.get(unit.NCIR, unit.PORTA)

#initialize wifi connection
wifiCfg.doConnect('your_SSID', 'your_Password')
m5mqtt.start()

temptext = M5TextBox(40,
                     180,
                     "BODY TEMP:",
                     lcd.FONT_DejaVu18,
                     0xFFFFFF,
                     rotate=0)
tempval = M5TextBox(210, 180, "0", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label5 = M5TextBox(40, 208, "", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)

while True:
    wait_ms(1000)
    temperatura = (str(ncir0.temperature + 4)
                   )  # sensor NCIR not so precise, add some value to correct
Exemple #18
0
    <p><a href="/?led=off"><button class="button button2">OFF</button></a      ></p>
    </html>"""
    return html


ip = wifiCfg.wlan_sta.ifconfig()

#create labels to display the information on the M5Stack screen
label1 = M5TextBox(0, 0, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(0, 12, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(0, 24, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(0, 50, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(120, 200, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)

response = None
wifiCfg.doConnect('SINGTEL-DD8F(2.4G)', 'fuewiexoay')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('192.168.1.117', 80))
s.listen(5)

if wifiCfg.wlan_sta.isconnected():
    label1.setText('wifi connected')
    label2.setText('Your IP Address is: ' + str(ip[0]))
else:
    label1.setText('wifi not connected')
    wait_ms(2)

while True:
    conn, addr = s.accept()
    request = conn.recv(1024)
    request = str(request)
Exemple #19
0
from m5stack import *
from m5ui import *
from uiflow import *
import wifiCfg
import imu
from time import sleep_ms
from math import fabs as abs
import urequests

setScreenColor(0x111111)

imu0 = imu.IMU()

wifiCfg.screenShow()
wifiCfg.autoConnect(lcdShow=True)
wifiCfg.doConnect('minicar', None)

setScreenColor(0x3797de)
label1 = M5TextBox(15, 140, "x:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=270)
label0 = M5TextBox(15, 115, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=270)

label2 = M5TextBox(45, 140, "y:", lcd.FONT_DejaVu18, 0xf10909, rotate=270)
label4 = M5TextBox(45, 115, "Text", lcd.FONT_DejaVu18, 0xf10909, rotate=270)

label3 = M5TextBox(18, 65, "STATE", lcd.FONT_DejaVu18, 0xf10909, rotate=270)
status = M5TextBox(42, 65, "S", lcd.FONT_DejaVu18, 0x009900, rotate=270)

stop_limit = 10  # 当范围为limit默认为停止

status_dict = {
    0: "S",