Jan 15, 2015 Tag: Arduino

Looking for Wisdom about Arduino

Ongoing attempt to collect know how about the Arduino. Will be updated as needed.

Updated on Nov 24, 2018

Overview:

1sheeld

Micropython

Firmware for ESP8266 boards

  1. Download from: https://www.micropython.org/download#esp8266

  2. MicroPython quick reference for the ESP8266

  3. Deploying the firmware:

    esptool.py --port /dev/ttyUSB0 erase_flash
    esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash \
               --flash_size=detect 0 esp8266-20180511-v1.9.4.bin
    

    Nodemcu:

    esptool.py --port /dev/ttyUSB0 erase_flash
    esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash \
               --flash_size=detect -fm dio 0 esp8266-20180511-v1.9.4.bin
    

Videos

Do a mqtt demo

Required: Nodemcu with MicroPython, laptop, mosquitto (sudo apt install mosquitto mosquitto-clients)

  1. Power up the Nodemcu. Do not connect usb cable. We want to work “over the air” only. We have enabled the Webrepl before and gave it a password.

  2. The Nodemcu will open up a WiFi network named MicroPython-nnnnnn. Pick your laptop and connect to that network. The WiFi WPA2 password is: micropythoN - note the capital ‘N’.

  3. Verify the network is working on your laptop and find the ip and watch out for the ip. Usually it would be 192.168.4.2:

    ➜  route
    should show a line with a route to 192.168.4.0
    
    ➜  hostname -I
    192.168.1.207 192.168.4.2 172.18.0.1 172.17.0.1
    
  4. Our laptop will work as server and mqtt broker. Start the mqtt broker in a terminal window:

    ➜  mosquitto -p 11883  -v
    
  5. In a second terminal window on the laptop run an mqtt client and subscribe to the house topic:

    ➜  mosquitto_sub -h 192.168.4.2 -p 11883 -t "house/#" -v
    ➜  # or
    ➜  mosquitto_sub -h 127.0.0.1   -p 11883 -t "house/#" -v
    
  6. In a third terminal window on the laptop now publish some mqtt messages:

    ➜  mosquitto_pub -h 192.168.4.2 -p 11883 -t house/s1 -m "a msg from s1"
    ➜  mosquitto_pub -h 192.168.4.2 -p 11883 -t house/s2 -m "a msg from s2"
    
  7. Now let’s connect to the webrepl of the Nodemcu. Go to http://micropython.org/webrepl/ (NO https - just http!), or, if you have that installed before on your machine, go to a local copy of webrepl at http://localhost/webrepl/webrepl.html

    Click ‘Connect’ and use the password you have set when enabling webrepl.

  8. And ‘bingo’, you should be on the command line (Python repl) of your ESP8266:

    >>> 2 + 2
    4
    
  9. Firewall? If you have that on your laptop, make sure that connections from the Nodemcu are allowed.

  10. Publish a message from you ESP8266 Nodemcu over the air to the broker and let the broker do its job:

    from umqtt.simple import MQTTClient
    c = MQTTClient("umqtt_client", '192.168.4.2', port=11883)
    c.connect()
    c.publish('house/nodemcu', b'Ich bin da.')
    
    #
    

Youtube

Previous topic

Looking for Wisdom about Ansible

Next topic

Looking for Wisdom about Bash

Tags

Archives

Languages

Recent Posts

This Page