Package: micropython-rockwren
micropython-rockwrenRockwren is amicropythondevice application framework to simplify the creation of
connected devices such as lights, switches, and sensors.  It is designed for the Raspberry Pi Pico W but also
runs on less capable devices such as the ESP8266.SeeQuick Startto get your first application running.Why call this package rockwren?TheNew Zealand rock wren (Pīwauwau)is a tiny but widely admired alpine bird that lives in the mountains of Fiordland in New Zealand. It's ability to
live life year round in a very harsh environment and it's small size seemed apt when thinking of a name for this
micropython package.Who should use Rockwren?Developers who would like to create micropython based devices with web, MQTT, AWS IoT, andHome Assistantsupport built in.What is the goal of the Rockwren project?Provide a micropython package that simplifies IoT device development.  Provide connectivity
out-of-the-box so the developer can focus their efforts on the specific capabilities of the device.FeaturesWeb interface for configuration and device controlMQTT client with certificate support (e.g. AWS IoT orMosquitto)Access Point mode for device configurationHome Assistant discovery via MQTTThe web interface supports:An extendable web interface for device specific controls and status displayMQTT, WiFi configurationA log viewerA device information viewerLinksChangelog:https://github.com/ccrighton/rockwren/blob/main/changelog.mdSource code repository:https://github.com/ccrighton/rockwrenDocumentation:https://github.com/ccrighton/rockwren/blob/main/docs/TOC.mdFind existing issues or raise a bug:https://github.com/ccrighton/rockwren/issuesPackage repository:https://pypi.org/project/micropython-rockwren/DependenciesRockwren depends on:MicropythonA fork of the Pimoroni Phew web server:PhewAn MQTT client:umqtt.simple2andumqtt.robust2byWojciech BanaśQuick StartInstall with ThonnySee thePico guidefor details on setting up Thonny and adding the Micropython firmware to yourPico Wor other similar device supporting micropython.Once you have Thonny installed, the rockwren package can be installed.SelectToolsthenManage packages....Entermicropython-rockwren, clickSearch on PyPI.Click onmicropython-rockwrenin the search results.Click onInstall.Once the installation has completed, close the package window.Rockwren is now installed on the Pico W.  Now install the sample application.Pico W LEDThis is a simple application that turns the onboard LED on and off from the web, home assistant, or via MQTT.Create a new file in Thonny, paste the following code into it and save asmain.py.  When prompted forWhere to save to?, chooseRaspberry Pi Pico.frommachineimportPinfromrockwrenimportmqtt_clientfromrockwrenimportrockwrenclassPicoWLED(rockwren.Device):def__init__(self):self.led=Pin("LED",Pin.OUT)super().__init__(name="PicoWLED")# Always call lastdefapply_state(self):ifself.state=="ON":self.led.on()elifself.state=="OFF":self.led.off()super().apply_state()# Always call lastdefcommand_handler(self,topic,message):ifmessage.get("state"):ifmessage.get("state").upper()=="ON":self.on()elifmessage.get("state").upper()=="OFF":self.off()super().command_handler(topic,message)# Always call lastdefdiscovery_function(self):returnmqtt_client.default_discovery(self.mqtt_client)rockwren.fly(PicoWLED())Run the current script. ClickRunandRun current script.2023-09-29 00:15:36 [info     / 136kB] Free storage: 568.0 KB
2023-09-29 00:15:36 [info     / 131kB] mqtt_server not set using default
2023-09-29 00:15:36 [info     / 129kB] mqtt_port not set using default
2023-09-29 00:15:36 [info     / 127kB] mqtt_client_cert not set using default
2023-09-29 00:15:36 [info     / 125kB] mqtt_client_key not set using default
essid=rockwren, password=12345678
2023-09-29 00:15:36 [info     / 123kB] Access point active
2023-09-29 00:15:36 [info     / 121kB] ('192.168.4.1', '255.255.255.0', '192.168.4.1', '0.0.0.0')
2023-09-29 00:15:36 [info     / 119kB] > starting web server on port 80This will start the device in access point mode.Connect to therockwrenwifi access point.In a browser navigate tohttp://192.168.4.1Enter your SSID and password and clickSubmitA restart page will be displayed.Once the device reboot it will connect to the SSID provided.Use the IP address from the console on boot, an IP address scanner or check your router settings to find the IP
address of your device.  One options isFingfor Android and iOS.  Choose the device calledrockwrenon the list displayed by the IP scanner or router.Reconnect to the same SSID and in a browser navigate to IP address of the device.ClickTOGGLEto turn the Pico W LED on and off.Shortcut to skip AP configurationCreate a file callenv.jsonwith the following JSON replacing theYOUR-SSIDANDYOUR-SSID-PASSWORD.mqtt_serverandmqtt_portcan be configured in this way too.  mqtt_port of 0 uses the default.{"ssid":"YOUR-SSID","password":"YOUR-SSID-PASSWORD","mqtt_server":"","mqtt_port":0,"first_boot":false}Copy to the device:mpremote cp env.json :PipkinIt is also possible to install from PyPI using thepipkintool for managing micropython distribution packages.Install pipkin.pip install pipkinInstallmicropython-rockwrenand dependencies.pipkin install micropython-rockwrenOther Example Device Applicationspico_led_lightpico_binary_sensorpico_temperaturepico_switchDocumentationAdditional documentation on configuring and developing new devices is in github:Rockwren DocsLicenseSource code license:GPL-3.0-or-laterDocumentation license:CC-BY-4.0