Removed init.py

parent 0745907d
import machine
import ubinascii
from umqtt.simple import MQTTClient
import config
import env
from Task import TasksList, Task
from board import Board
from callbacks import _hq_changed_status, _hq_changes_status
from tasks import _updates_led, _stay_connected, _work
def init():
env.status = None
# Create interface to the board
env.board = Board(callback_button=_hq_changes_status)
# Create an instance to connect to mqtt server
env.mqtt = MQTTClient(
ubinascii.hexlify(machine.unique_id()),
config.MQTT_SERVER,
user=config.MQTT_USER,
password=config.MQTT_PASSWORD
)
# Set the callback to the changes of the mqtt's topic
env.mqtt.set_callback(_hq_changed_status)
# Create a list of tasks
env.tasks_list = TasksList()
# Create task to update the LED
env.tasks_list["update_status"] = Task(period=500, task=_updates_led)
# Create task to hold the connection
env.tasks_list["stay_connected"] = Task(period=5000, task=_stay_connected)
# Create the main task
env.tasks_list["work"] = Task(period=2000, task=_work)
import machine
import micropython
import ubinascii
from umqtt.simple import MQTTClient
from utime import sleep_ms
import config
import env
import interrupt
from Task import TasksList, Task
from board import Board
from init import init
from callbacks import _hq_changed_status, _hq_changes_status
from tasks import _updates_led, _stay_connected, _work
micropython.alloc_emergency_exception_buf(100)
init()
# tasks_list["update_status"].init()
env.tasks_list.init_all()
# Create interface to the board
env.board = Board(callback_button=_hq_changes_status)
# Create an instance to connect to mqtt server
env.mqtt = MQTTClient(
ubinascii.hexlify(machine.unique_id()),
config.MQTT_SERVER,
user=config.MQTT_USER,
password=config.MQTT_PASSWORD
)
# Set the callback to the changes of the mqtt's topic
env.mqtt.set_callback(_hq_changed_status)
# Create a list of tasks
env.tasks_list = TasksList()
# while interrupt.isRunning():
# if not interfaces.sta.try_to_connect(config.WIFI_SSID, config.WIFI_KEY):
# _status = None
# print("Failed to connect to Wi-Fi")
# continue
#
# try:
# mqtt.connect()
# mqtt.subscribe(config.MQTT_TOPIC)
# print("Connected to mqtt server")
#
# except Exception as e:
# print("Error to connect to mqtt server")
# print("> {}".format(e))
# continue
#
# break
# Create task to update the LED
env.tasks_list["update_status"] = Task(period=500, task=_updates_led)
# Create task to hold the connection
env.tasks_list["stay_connected"] = Task(period=5000, task=_stay_connected)
# Create the main task
env.tasks_list["work"] = Task(period=2000, task=_work)
# Start the tasks
env.tasks_list.init_all()
while interrupt.isRunning():
sleep_ms(500)
# Stop all tasks
env.tasks_list.deinit_all()
env.board.set_led(Board.LED_WHITE)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment