def Install(aName: str): Net = Connect(Conf.STA_ESSID, Conf.STA_Paswd, Conf.STA_Net) if (Net.isconnected()): upip.install(aName) else: print('Cant connect WiFi')
import network sta_if = network.WLAN(network.STA_IF) if not sta_if.isconnected(): print('Connecting to network...') sta_if.active(True) sta_if.connect(wc.SSID, wc.PASSWORD) while not sta_if.isconnected(): time.sleep(1) print('Network config:', sta_if.ifconfig()) try: import logging except ImportError: temporize() do_connect() from machine import reset from upip import install install('logging') temporize(3) reset() def no_debug(): import esp # this can be run from the REPL as well esp.osdebug(None) gc.collect()
# Micropython a9g example # Source: https://github.com/pulkin/micropython # Author: pulkin # Demonstrates how to communicate via http using requests library # Get online import cellular cellular.gprs("internet", "", "") # Import requests (download if necessary) try: import urequests except ImportError: import upip upip.install("micropython-urequests") import urequests r = urequests.get("http://httpstat.us/200") print(r.status_code, r.text)
# Install script for dependencies using upip import machine import network import time import upip # Connect to LAN if not already done by boot.py try: lan except: print("Starting network connection...") lan = network.LAN(mdc=machine.Pin(16), mdio=machine.Pin(17), power=None, phy_type=network.PHY_LAN8720, phy_addr=0) lan.active(1) # Wait for network while lan.ifconfig()[0] == '0.0.0.0': print("Waiting for network connection...") time.sleep(2) # Install microdot print("Network connection established, installing microdot...") upip.install('microdot') print("Installation finished.")
import sys import gc gc.collect() gc.collect() try: from utime import time, sleep except: print('ERROR: missing dependency `utime`') sys.exit(1) gc.collect() try: import urequests except: import upip upip.install('micropython-urequests') import urequests gc.collect() class Credentials: @classmethod def create_from_json_string(cls, cred_str): cred_obj = json.loads(cred_str) return cls(cred_obj['host'], cred_obj['user'], cred_obj['password']) def __init__(self, host, user, password): self._host = host self._user = user.encode('utf-8') self._password = password.encode('utf-8')
import upip upip.install('umqtt.robust') import tatu import machine import micropython import network import esp import utime import ujson esp.osdebug(None) import gc gc.collect() from umqtt.robust import MQTTClient data = None topicPrefix = "dev/" def sub_cb(topic, msg): #print(topic, msg) if "RES" not in topic: tatu.main(data, msg) station = network.WLAN(network.STA_IF) station.active(True)
import time import uos import upip from boot import network_connect SLEEP_TIME = 3 ip = network_connect() print("ip: {}".format(ip)) print("sleeping {} seconds".format(SLEEP_TIME)) time.sleep(SLEEP_TIME) install_location = "lib" install_names = {"micropython-logging": "logging.py"} for install_name, lib_name in install_names.items(): try: uos.stat("./{}/{}".format(install_location, lib_name)) print("exists {}".format(install_name)) except OSError: upip.install("{}".format(install_name)) print("installed {}".format(install_name))
try: import logging except: import upip upip.install('micropython-logging')
def install(): upip.install('micropython-logging')
def getmodule(mod_name): print("Installing {}".format(mod_name)) upip.install('micropython-' + mod_name)
import network import upip from config import config import utime as time wifi_name = config['wifi']['name'] wifi_pass = config['wifi']['pass'] sta_if = network.WLAN(network.STA_IF) sta_if.active(True) sta_if.connect(wifi_name, wifi_pass) # Wait until network is connected while not sta_if.isconnected(): time.sleep_ms(500) print(".") upip.install('micropython-umqtt.simple') upip.install('micropython-umqtt.robust')
import upip upip.install("micropython-umqtt.simple2") import sys sys.path.reverse()
def instalUasyncio(): import upip upip.install('micropython-uasyncio')
try: from grown import setup, run_grown import webrepl import machine grown = setup() webrepl.start() print("reset %s: " % machine.reset_cause()) if machine.reset_cause() in [machine.HARD_RESET, machine.PWRON_RESET]: import upip upip.install('grown') machine.reset() from grown.light_control import add_light_control from grown.data_control import add_data_control from bh import BH1750 except ImportError: import network import ujson file_ptr = open("settings_store.json", "r") store = ujson.loads(file_ptr.read()) sta_if = network.WLAN(network.STA_IF) sta_if.active(True) sta_if.connect(store['wlan']['ssid'], store['wlan']['password']) import upip upip.install('grown') import machine
def upip_uasync(self): import os import upip if not 'lib' in os.listdir(): upip.install('micropython-uasyncio.core')
# Wifi is needed for installing the packages networkConfig.connect_wifi() # TODO: test later with list pkgList = ["micropython-io-0.1.tar.gz", "micropython-xmltok2-0.2.tar.gz", "micropython-xml.etree.ElementTree-0.1.1.tar.gz", "micropython-umqtt.simple-1.3.4.tar.gz"] try: f = open('lib/io.py', "r") io_exists = True f.close() print('io.py already installed.') except OSError: io_exists = False if not io_exists: upip.install("micropython-io") try: f = open('lib/xmltok2.py', "r") xmltok2_exists = True f.close() print('xmltok2.py already installed.') except OSError: xmltok2_exists = False if not xmltok2_exists: upip.install("micropython-xmltok2") try: f = open('lib/xml/etree/ElementTree.py', "r") xml_exists = True f.close()
wlan.connect(ssid, passphrase) while not wlan.isconnected(): pass print('Oh Yes! Get connected') print('Connected to ' + ssid) print('MAC Address: ' + ubinascii.hexlify(network.WLAN().config('mac'),':').decode()) print('IP Address: ' + wlan.ifconfig()[0]) print('') try: import umqtt.simple import umqtt.robust import hmac except: upip.install("micropython-umqtt.simple") upip.install("micropython-umqtt.robust") upip.install("micropython-hmac") from umqtt.simple import MQTTClient from crypt import CryptAes STATE = 0 i2cAddrGolden = [60, 72, 83] IMU_I2C_ADDR = 83 TMP_I2C_ADDR = 72 IMU_DATA_FORMAT_REG = 0x31
def do_install_requirements(): try: import logging # noqa except Exception: import upip upip.install("micropython-logging")
# Example of how to use upip # First setup network # see wlan module for wlanconfig file # pip install with packages for micropython (prefix micropython-) # Check on the package, there are probably limitations # profit import network import wlanconfig def do_connect(essid, password): import network wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print('connecting to network...') wlan.connect(essid, password) while not wlan.isconnected(): pass print('network config:', wlan.ifconfig()) if __name__ == "__main__": do_connect(wlanconfig.ESSID, wlanconfig.PASSWORD) import upip upip.install('micropython-uuid') upip.install('micropython-umqtt.simple2') upip.install('micropython-umqtt.robust2')
def shutil(): print("System download > (initial octopus modules)") import upip print("Installing shutil") upip.install("micropython-shutil") print("Running deploy")
import upip packages = "picoweb", "pycopy-ulogging" for package in packages: upip.install(package)