Thursday, May 2, 2019

Starting a MySQL Server and PhpMyAdmin Docker containers

MacOS Mojave 10.14.4
Docker Engine: 18.09.0


Goal:
  • To have a docker container running a MySQL Server instance and another running the PhpMyAdmin.

Install:
  • Download the MySQL Community Edition image:
    • docker pull mysql:5.7.26
  • Start a new Docker container for the MySQL Community Server:
    • docker run --name=mysql1 -p 3306:3306 -e MYSQL_RANDOM_ROOT_PASSWORD=yes -d mysql:5.7.26
  • Or create and start the container:
    • docker container create --name=mysql1 -p 3306:3306 -e MYSQL_RANDOM_ROOT_PASSWORD=yes mysql:5.7.26
    • docker container start mysql1
  • The container appears in the list of running containers when you run the docker ps command:
    • docker ps
    • ============================================
    • CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS                   PORTS                 NAMES
    • 188d9a1f7d0d        mysql:5.7.26            "docker-entrypoint.s…"   25 minutes ago      Up 25 minutes       0.0.0.0:3306->3306/tcp, 33060/tcp   mysql1
    • ============================================
  • The -d option used in the docker run command above makes the container run in detached mode. These are other options available:
    • -d, --detach - Detached mode: run command in the background
    • -i, --interactive - Keep STDIN open even if not attached
    • -t, --tty - Allocate a pseudo-TTY
    • -u, --user string  -  Username or UID (format: <name|uid>[:<group|gid>])
    • -w, --workdir string  -  Working directory inside the container
  • Use this command to monitor the output from the any container:
    • docker logs <Container-ID>
  • Once initialization is finished, the command's output is going to contain the random password generated for the root user; check the password with, for example, this command:
    • docker logs mysql1 2>&1 | grep GENERATED
    • GENERATED ROOT PASSWORD: aSS3sNArecAMEsH3w=Os.it0N.i
  • Once the server is ready, you can run the mysql client within the MySQL Server container you just started and connect it to the MySQL Server using the password generated:
    • docker exec -it mysql1 mysql -u root -p
  • You can access the server from a client running on another computer via network, or from the computer were docker is running, using the command:
    • mysql -u root -p -h <IP-OF-THE-COMPUTER-WHERE-DOCKER-IS-RUNNING>
  • Because we used MYSQL_RANDOM_ROOT_PASSWORD=yes, after you have connected a mysql client to the server you must reset the server root password by running these commands:
    • ALTER USER 'root'@'localhost' IDENTIFIED BY '<password>';
    • ALTER USER 'root'@'%' IDENTIFIED BY '<password>';
    • FLUSH PRIVILEGES;
  • To run MySql Server again, after close Docker, you need to start Docker and run:
    • docker container start mysql1

Additional Info:
  • Docker requires your command (e.g. CMD) to keep running in the foreground. Otherwise, it thinks that your applications stops and shutdown the container. The problem is that some application does not run in the foreground. In this situation, you can add tail -f /dev/null to your command. Even if your main command runs in the background, your container doesn’t stop because tail is keep running in the foreground.
  • You can run the container that doesn't have a command running in foreground and open a terminal inside the container by using:
    • docker run --entrypoint "/bin/sh" -it alpine/git
    • docker run --entrypoint "/bin/bash" -it alpine/git
  • You can stop the container using the command:
    • docker stop mysql1
  • You can also remove the container using the command:
    • docker rm mysql1
  • To connect to MySQL server remotely using MySQL client, edit the /etc/mysql/mysql.conf.d/mysqld.cnf configuration file:
    • sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
  • And change the "bind-address" from  127.0.0.1  to:
    • bind-address = 0.0.0.0

Install PhPMyAdmin:
  • Download and run PhpMyAdmin docker image:
    • docker run --name myadmin -d -e PMA_ARBITRARY=1 -p 8080:80 phpmyadmin/phpmyadmin
    • docker ps
    • ============================================
    • CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                               NAMES
    • 188d9a1f7d0d        mysql:5.7.26            "docker-entrypoint.s…"   25 minutes ago      Up 25 minutes       0.0.0.0:3306->3306/tcp, 33060/tcp   mysql1
    • 56e041e28d47        phpmyadmin/phpmyadmin   "/run.sh supervisord…"   20 minutes ago         Up 20 minutes          9000/tcp, 0.0.0.0:8080->80/tcp      myadmin
    • ============================================
  • Access the address:
    • http://localhost:8080
      • Server: localhost
      • Username: root
      • Password: aSS3sNArecAMEsH3w=Os.it0N.i
  • To run PhpMyAdmin again, after close Docker, you need to start Docker and run:
    • docker container start myadmin

Backup and Restore MySQL databases:

  • Backup with data:
    • mysqldump -u root -p iotdb > iotdb_bkp20190627.sql
  • Backup without data, only structure:
    • mysqldump -u root -p -d iotdb > iotdb_bkp20190627.sql
  • Backup compatible with: (ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, or no_field_options)
    • mysqldump --compatible=ansi -u root -p iotdb > iotdb_bkp20190627.sql
  • Restore:
    • mysqldump -u root -p iotdb < iotdb_bkp20190627.sql

References:

Wednesday, March 6, 2019

Using AWS SDK for Python to store files on S3 (Simple Storage Service)

MacOS 10.14.3
Python 3.7.2
Boto3 AWS SDK for Python


Goal:
  • Create a Bucket in AWS S3, list the Buckets, upload, list and delete files stored in the Bucket.
Info:
  • Amazon S3 buckets, which are similar to file folders, store objects, which consist of data and its descriptive metadata.
  • There is no limit to the amount of objects an IT professional can store in a bucket, though buckets cannot exist inside of other buckets.
  • The S3 API to list files in the bucket (ListObjects) is paginated, returning up to 1000 keys (filenames) at a time, it also includes information like size, modified date, and ETag (md5 hash).
Install:
  • Using the Terminal:
    • pip3 install boto3
  • Create the credential file. By default, its location is at ~/.aws/credentials:
    • nano ~/.aws/credentials
      • [default]
      • aws_access_key_id = YOUR_ACCESS_KEY
      • aws_secret_access_key = YOUR_SECRET_KEY
Tests (using python3):
  • List of Buckets:
    • import boto3
    • s3c = boto3.client('s3')
    • response = s3c.list_buckets()
    • buckets = [bucket['Name'] for bucket in response['Buckets']]
    • print(buckets)
  • Create a new Bucket:
    • import boto3
    • s3c = boto3.client('s3')
    • s3c.create_bucket(Bucket='my-bucket')
  • Check if a bucket exist:
    • import boto3
    • s3r = boto3.resource('s3')
    • try:
      • s3r.meta.client.head_bucket(Bucket='my-bucket')
    • except Exception as e:
      • print('Bucket does not exist')
      • print(str(e))
  • Delete a Bucket:
    • import boto3
    • s3r = boto3.resource('s3')
    • bucket = s3r.Bucket('my-bucket')
    • # To completely remove the bucket itself (must be empty?):
    • bucket.delete()
  • List files (keys) in the Bucket:
    • import boto3
    • s3c = boto3.client('s3')
    • resp = s3c.list_objects_v2(Bucket='my-bucket')
    • try:
      • for obj in resp['Contents']:
        • print(obj['Key'], obj['LastModified'], obj['Size'], obj['ETag'])
    • except:
      • print('no files in the bucket')
    • Note: If there aren’t any files (keys), the ListObjects API doesn’t include a “Contents” key in the response.
  • Upload a file to the Bucket:
    • import boto3
    • s3r = boto3.resource('s3')
    • s3r.meta.client.upload_file('/tmp/linux.jpg', 'my-bucket', 'linux.jpg')
  • Download a file from the Bucket:
    • import boto3
    • s3r = boto3.resource('s3')
    • try:
      • s3r.Bucket('my-bucket',).download_file('linux.jpg', 'my_local_linux.jpg')
    • except:
      • print('file does not exist')
  • Delete a file from the Bucket:
    • import boto3
    • s3r = boto3.resource('s3')
    • obj = s3r.Object('my-bucket', 'linux.jpg')
    • obj.delete()
  • Delete all files from the Bucket:
    • import boto3
    • s3r = boto3.resource('s3')
    • bucket = s3r.Bucket('my-bucket')
    • bucket.objects.all().delete()
References:

If you like this content, feel free to

Sunday, January 13, 2019

ESP32 and ESP8266 - Configuring Arduino IDE and Updating firmware

MacOS 10.14.2
Arduino IDE 1.8.7


Goal:

  • Configure Arduino IDE to develop and compile code to the ESP32 boards. Also download and install tools and SDKs files to update the firmware on ESP32 devices.

Install:
  • Installing Boards support on Arduino IDE:
    • Start Arduino IDE and open Preferences window (File -> Preferences);
    • Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json, https://dl.espressif.com/dl/package_esp32_index.json into Additional Board Manager URLs field;
    • Open Boards Manager from Tools -> Board menu and install esp8266 (zzz...);
    • Open Boards Manager from Tools -> Board menu and install esp32 by Espressif Systems (zzz...);
  • Installing Libraries on Arduino IDE:

  • Download Flash Tools (ESP8266 & ESP32):
    • Download the latest Flash Tools here.
  • Download firmware:
    • ESP32:
      • Download the latest SDK here.
    • ESP8266:
      • Download the latest SDK here or here.
  • Updating Firmware:
    • Connect ESP to a computer.
    • Windows:
      • run the ESPFlashDownloadTool_v3.6.5.exe
      • Choose the right board model (ESP8266,  ESP8265, ESP32)
      • Check, locate the binary files and address for bootloader, singleapp partition and user application:
        • ESP32:
          • 0x1000: bootloader.bin
          • 0x4000: partitions_singleapp.bin
          • 0x10000: helloworld-esp32.bin (the user main application code)
        • ESP8266:
          • 0x0: boot_v1.7.bin
          • 0x1000: user1.2048.new.5.bin
          • 0x3E000: blank.bin
          • 0x7C000: esp_init_data_default_v08.bin
          • 0x7E000: blank.bin
      • Choose a COM port
      • Choose Baud Rate 460800
      • Flash the *.bin files

Tests:
  • Open Arduino IDE, compile and upload a simple example (e.g., Blink)


Troubleshooting:
  • Fix for "sketch is too big" on ESP32 boards:
    • Links:
    • Files to change on Windows:
      • <?>\hardware\espressif\esp32\boards.txt
      • <?>\espressif\esp32\tools\partitions\default.csv
    • Files to change on MacOS:
      • /Users/marcus/Library/Arduino15/packages/esp32/hardware/esp32/1.0.1/boards.txt
      • /Users/marcus/Library/Arduino15/packages/esp32/hardware/esp32/1.0.1/tools/partitions/default.csv
    • boards.txt:
      • lolin32.upload.maximum_size=1638400
    • default.cvs:
      • # Name,   Type, SubType, Offset,  Size, Flags
      • nvs,      data, nvs,     0x9000,  0x5000,
      • otadata,  data, ota,     0xe000,  0x2000,
      • app0,     app,  ota_0,   0x10000, 0x190000,
      • app1,     app,  ota_1,   0x1A0000,0x190000,
      • eeprom,   data, 0x99,    0x330000,0x1000,
      • spiffs,   data, spiffs,  0x331000,0x0CF000,
    • Obs: The board restarts itself after this change, maybe it is related. Don't know for sure. 
Info:
  • ESP8266 x ESP32 - Pros and Cons
  • ESP32 Specification:
    • Number of cores: 2
    • Architecture: 32 bit
    • Wi-Fi, Bluetooth
    • RAM: 512 KB
    • FLASH: 16 MB
    • GPIO Pins: 36
    • Communication Protocols: SPI, IIC, I2S, UART, CAN
    • ADC channels: 18 channels
    • ADC Resolution: 12-bit
    • DAC channels: 2
    • DAC Resolution: 8-bit

Arduino Board Configurations:

  • ESP8266:
    • Wemos D1 mini (GPIO02 = LED):
      • Menu Tools -> Board -> LOLIN(WEMOS) D1 R2 & mini
  • ESP32:
    • ESP32 Mini Kit (GPIO02 = LED):
      • Menu Tools -> Board -> WEMOS D1 MINI ESP32
        • Port:  SLAB_USBtoUART
      • Menu Tools -> Board -> MH ET LIVE ESP32MiniKit
    • ESP32 Lolin 32 lite (GPIO22 = LED):
      • Menu Tools -> Board -> SparkfFun ESP32 Thing
        • Upload Speed: 115200
      • Menu Tools -> Board -> WEMOS LOLIN32
        • Upload Speed: 115200
    • ESP32-Camera:
      • Menu Tools -> Board -> ESP32 Dev Module
    • WEMOS D1 R32 (Uno) (GPIO02 = LED):
      • Menu Tools -> Board -> WEMOS D1 MINI ESP32
        • Upload Speed: 115200

References:
If you like this content, feel free to

Monday, November 5, 2018

MacOS commands

MacOS commands



  • Task Manager
    • <command><option><esc>
  • Screen Shot:
    • <command><option><h><m>   ->   Minimize all windows
    • <command><shift><3>   ->  copy entire screen to an image on Desktop;
    • <command><shift><4> + <space> + click   ->   copy the select window to an image;
    • <command><shift><4> + define a custom area with the mouse   ->  copy the selected area to an image;
    • <command><shift><5>
  • Ifconfig  ->  Find your IP Address;
  • miniterm.py /dev/tty.usbserial-1420 115200   ->   Connect to serial device;
  • <command><shift><g>   ->  "Go to folder" in Finder 
  • sudo chflags nohidden(or hidden) directoryname   ->   directoryname that you want to see(or not) in Finder. (log out and back in)
  • defaults write com.apple.finder AppleShowAllFiles TRUE   ->   Showing all files in Finder. (log out and back in)
  • SSH:
    • Check if SSH is enabled:
      • sudo systemsetup -getremotelogin
    • Enable / Disable SSH server (remote access):
      • sudo systemsetup -setremotelogin on
      • sudo systemsetup -setremotelogin off
  • sudo nmap -sn -PE 192.168.1.0/24   ->   Ping all 256 IP's of the class C network 192.168.1.0. Using /24 will search 256 address, /23 will search 512 address, /22 will search 1024. Options meaning:  -sn (No port scan) -PE (ICMP ping echo).
  • ping -c 3 192.168.1.255 | grep 'bytes from' | awk '{ print $4 }' | sort | uniq   ->   Ping the broadcast address to return all devices on the network.
  • ping 192.168.1 | arp -a   ->   Ping all IP's and return their MAC address.
  • <command><option><esc>   ->   The basic “Force Quit Applications” window, which can be thought of as a simple task manager for Mac OS X.
  • <command><shift><Dot>   ->   Show hidden files on Mac via Finder. Repeat it to hide them again
If you like this content, feel free to

Installing Tools on Macbook Air

macOS Mojave 10.14.1
Xcode 10.1


Goal:

  • Install development tools on MacbookAir (e.g. Arduino IDE, Fritzing, Python, MicroPython, Brew, Sourcetree Bitbucket Sync, NodeJS).

  
ToDo:


Status:

  • 2018.11.05 - Working on it.

Install:

  • Installing Xcode:
    • Install Xcode from the App Store.
    • Open Xcode and install "complement"
  • Install Xcode’s separate Command Line Tools app:
    • Open Terminal:
    • xcode-select --install
    • OR Download it from https://developer.apple.com/download/more/ and install manually
  • Install Homebrew:
    • ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    • Enter your macbook user password
  • Configure Path:
    • nano ~/.bash_profile
    • Write the text below:
    • export PATH=/usr/local/bin:$PATH
    • Save the file using <control><o> and exit with <control><x>. Then activate the changes with the command below:
    • source ~/.bash_profile
  • Check that Homebrew was successfully installed:
    • brew doctor
    • This should be the output:
    • Your system is ready to brew.
    • brew update
  • Installing Python3:
    • Search for everything you can install, related to python:
    • brew search python3
    • python3 --version
    • Pip, Setuptools, and Wheel have also been installed.
  • Check if it is a 32 or 64 bits (python2 and python3)
    • python
    • import sys
    • is_64bits = sys.maxsize > 2**32
  • Python Virtual Environments:
    • Virtual environments enable you to have an isolated space on your computer for Python projects, ensuring that each of your projects can have its own set of dependencies that won’t disrupt any of your other projects. You can set up as many Python programming environments as you would like. Each environment is basically a directory or folder in your computer that has a few scripts in it to make it act as an environment.
    • Create a folder to python virtual environments:
      • mkdir ~/development
      • cd ~/development
      • mkdir python_envs
    • Installing Virtualenvwrapper:
      • pip3 install virtualenvwrapper
      • nano ~/.bash_profile
        • export WORKON_HOME=~/development/python_envs
        • MacOS:
          • export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
          • source /usr/local/bin/virtualenvwrapper.sh
        • Linux:
          • export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
          • source ~/.local/bin/virtualenvwrapper.sh
        • Windows:
          • pip install virtualenvwrapper-win
          • In Windows, the default path for WORKON_HOME is %USERPROFILE%\Envs
        • Close the terminal and open it again, to reload the bash_profile.
    • Creating a new environment (this creates the my_project folder inside $WORKON_HOME folder):
      • mkvirtualenv -p python3 my_project
    • To use this environment, you need to activate it:
      • cd $WORKON_HOME/my_project
      • workon my_project
    • Within the virtual environment, you can use the command python instead of python3, and pip instead of pip3 if you would prefer.
      • pip3 install django
    • To get out of the virtual environment:
      • deactivate
    • To delete the virtual environment created:
      • rmvirtualenv my_project
  • Installing Sourcetree:
    • Download at https://www.sourcetreeapp.com/
    • Install and clone repositories at /Users/<username>/development
  • Installing NodeJS:
  • Bash History behavior:
    • Note that the history file is automatically truncated to the size of HISTSIZE (500 by default) if the user does not explicitly set the size differently. HISTFILESIZE will be automatically set with the same value of HISTSIZE, so don't need to worry about it.
    • There are two lists of commands, one in memory and another in file. The setting for HISTCONTROL acts over the memory list. When you type a command it will be appended to the list. If the command to add is equal to the last command in the list and the option ignoredups is set, the command will be discarded.
    • Add HISTSIZE and HISTCONTROL to ~/.bash_profile:
      • nano ~/.bash_profile
        • export HISTSIZE=70000
        • export HISTFILESIZE=70000
        • export HISTCONTROL=ignoredups:erasedups
        • shopt -s histappend
        • PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"
    • Close the terminal and open again to apply the changes.
Info:

References:
If you like this content, feel free to

Thursday, August 23, 2018

Installing Ubuntu 18.04 32bits on Raspberry Pi 3

Ubuntu 18.04 32bits
Raspberry Pi 3
Python 2.7.15 / 3.6.5
NodeJS 8.10.0
MySQL 5.7.23


Goal:
  • Install Ubuntu on Raspberry Pi 3 with Python, Mosquitto, MySQL and NodeJS.

Status:
  • 2018.09.15 - Devices don't work for more than 5 min. It dosen't responds to ping. As these devices (Temp/Hum and Door sensors) only read sensors and publish to Broker, maybe the problem is with this version of Broker or an incompatibility with Ubuntu 18.04 for Raspberry Pi 3, or a hardware issue. When we pointed out all devices to other version of Broker in another computer, there's no problem anymore. Action: Mount another machine, with Ubuntu Mate 16.04.2 running on Raspberry Pi 2 to be an IoT Server.
  • 2018.08.23 - Ubuntu, Python, MySQL, Mosquitto and NodeJS are working.
Installing Ubuntu:
  • Download Ubuntu Image
  • Install DDRescue and unzip:
  • sudo apt-get install gddrescue xz-utils
  • unxz ubuntu-18.04-preinstalled-server-armhf+raspi3.img.xz
  • Identify MicroSD device name (/dev/sdX) and write to it:
  • lsblk
  • sudo ddrescue -D --force ubuntu-18.04-preinstalled-server-armhf+raspi3.img /dev/sdX
  • First Boot with the SD card: (User: ubuntu  Password: ubuntu)
  • Connect with WiFi:
    • nano /etc/netplan/*.yaml  (e.g. 50-cloud-init.yaml)
      • For wireless dhcp addressing:


network:
  version: 2
  renderer: networkd
  wifis:
    wlp3s0:
      dhcp4: yes
      access-points:
        "network_ssid_name":
          password: "**********"


Finishing the Wifi configuration:
  • sudo netplan --debug generate      # make config files
  • sudo netplan apply       # apply new configuration
  • reboot.      # must reboot

  • Once connected to Internet, installing optional PPAs:
  • sudo add-apt-repository ppa:ubuntu-raspi2/ppa
  • sudo apt update
  • Upgrade new packages (optional):
    • sudo apot upgrade
  • Change server hostname (optional):
    • sudo hostnamectl set-hostname <HOSTNAME>
    • sudo nano /etc/cloud/cloud.cfg
    • Change  preserve_hostname: false  to:
    • preserve_hostname: true
    • sudo nano /etc/hosts
    • Add a new line after  "127.0.0.1 localhost"
    • 127.0.1.1 <HOSTNAME>
  • Installing Python:
    • sudo apt install python python3 python-minimal python-pip python-mysqldb
    • Install Paho MQTT Python Client:
    • pip install paho-mqtt
    • Install SQLAlchemy:
    • pip install SQLAlchemy==1.2.11
  • Install Mosquitto MQTT Server:
    • sudo apt update
    • sudo apt-get install mosquitto mosquitto-clients
    • Start Mosquitto Server:
      • mosquitto -d
  • Installing MySQL:
    • sudo apt install mysql-server
    • sudo mysql_secure_installation
    • To configure the root account to authenticate with a password, run the following "alter user" command. Then, run "flush privileges" which tells the server to reload the grant tables and put your new changes into effect:
    • sudo mysql
    • alter user 'root'@'localhost' identified with mysql_native_password by 'password';
    • flush privileges;
    • Creating a new user (iotdbuser) and granting privileges:
    • create user 'iotdbuser'@'%' IDENTIFIED BY 'user_password';
    • grant all privileges on iotdb.* to 'iotdbuser'@'localhost';
    • To connect to MySQL server remotely using MySQL client, edit the /etc/mysql/mysql.conf.d/mysqld.cnf configuration:
    • sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
    • And change the "bind-address" from  127.0.0.1  to:
    • bind-address = 0.0.0.0
    • And grant access to root user from network:
    • grant all on *.* to root@'%' identified by 'root-password';
    • Once ready, reboot your MySQL server:
    • sudo service mysql restart
  • Installing NodeJS:
    • sudo apt install nodejs npm
    • Create a directory for the NodeJS projects:
    • mkdir ~/iot/wsk_cp
    • cd ~/iot/wsk_cp
    • npm init –y
    • sudo npm install mysql
    • sudo npm install express -g
    • sudo npm install request -g
    • sudo npm install ws -g

Testing:
  • Testing Mosquitto:
  • mosquitto_sub -t "outTopic"
  • mosquitto_pub -t "outTopic" -m "hello world!"
  • Testing MySQL:
  • mysql -V
  • sudo mysql
  • select user,authentication_string,plugin,host FROM mysql.user;
  • Connect to MySQL server over network:
  • mysql -u root -p '' -h <MYSQL_HOST_IP>
Troubleshooting:
    • .
    References:
    If you like this content, feel free to

    Sunday, July 29, 2018

    Installing MicroPython on ESP8266 and ESP32

    Windows 10
    MacOS Mojave 10.14.1
    MicroPython 1.9.4.8


    Goals:

    • Use Python for Microcontrollers (MicroPython) on Wemos D1 mini (ESP8266) and ESP32.

    Info:
    • MicroPython is a condensed, optimized code of Python 3 that has been loaded in hardware. This means rather than having to have an interpreter run on an operating system to execute the Python code, the MicroPython chip can run the Python code directly on the hardware. No operating system is needed. In fact, MicroPython has basic file I/O built in.
    • After a fresh install and boot the device configures itself as a WiFi access point (AP) that you can connect to. The ESSID is of the form MicroPython-xxxxxx where the x’s are replaced with part of the MAC address of your device (so will be the same every time, and most likely different for all ESP8266 chips). The password for the WiFi is micropythoN (case-sensitive). Its IP address will be 192.168.4.1 once you connect to its network.

    Installing Micropython:
    • Install the latest EspTool (2.5.0+):
    • Windows: using Windows Terminal (cmd):
      • For using ESP32 on WIndows we need to install USB Driver:
        • Download the driver and follow the instructions here.
      • pip install esptool --upgrade
      • pip3 install adafruit-ampy --upgrade
      • set AMPY_PORT=COM?
    • Linux:
      • sudo pip install esptool --upgrade
      • pip3 install adafruit-ampy --upgrade
      • export AMPY_PORT=/dev/ttyUSB0
    • MacOS: using Terminal:
      • pip3 install esptool --upgrade
      • pip3 install adafruit-ampy --upgrade
      • export AMPY_PORT=/dev/tty.usbserial-1420
      • For using ESP32 on MacOS we need to install USB Driver:
    • Erase the flash (ESP8266 and ESP32):
      • Windows:
        • locate the latest esptool.py installed:
          • cd \
          • dir /S esptool.py
        • python <esptool-path>/esptool.py --port COM? erase_flash
      • Linux:
        • python <esptool-path>/esptool.py --port /dev/ttyUSB0 erase_flash
      • MacOS:
        • python <esptool-path>/esptool.py --port /dev/tty.usbserial-1420 erase_flash
    • Deploy the new firmware on ESP8266:
      • Download MicroPython image here:
      • Windows:
        • python <esptool-path>/esptool.py --port COM? --baud 460800 write_flash --verify -fs=detect -fm dio 0 \users\Marcus\Downloads\esp8266-20180511-v1.9.4.bin
      • Linux:
        • python <esptool-path>/esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --verify -fs=detect -fm dio 0 /home/marcus/esp8266-20180511-v1.9.4.bin
      • MacOS:
        • python <esptool-path>/esptool.py --port /dev/tty.usbserial-1420 --baud 460800 write_flash --verify -fs=detect -fm dio 0 /Users/marcus/Downloads/esp8266-20180511-v1.9.4.bin
    • Deploy the new firmware oESP32:
      • Download MicroPython image here:
      • Windows:
        • python <esptool-path>/esptool.py --chip esp32 --port COM4 write_flash -z 0x1000 \users\Marcus\Downloads\esp32-20180730-v1.9.4-410-g11a38d5dc.bin
      • Linux:
        • python <esptool-path>/esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 /home/marcus/esp32-20180730-v1.9.4-410-g11a38d5dc.bin
      • MacOS:
        • python <esptool-path>/esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART write_flash -z 0x1000 /Users/marcus/Downloads/esp32-20180730-v1.9.4-410-g11a38d5dc.bin
    • Installing Libraries not included in MicroPython using upip and REPL:
      • Connecting to Internet:
        • import network
        • station = network.WLAN(network.STA_IF)
        • station.active(True)
        • station.connect('ssid', 'password')
        • print('Connected: {}'.format(station.isconnected()))
        • ipadd=station.ifconfig()
        • print('IP: {}'.format(ipadd))
      • import upip
      • Use upip to install any library available on PyPI:
        • upip.install('micropython-umqtt.robust')
        • upip.install('micropython-umqtt.simple')
    Testing:
    • List files on the board using Ampy, MFPShell or RShell:
      • ampy ls (needs AMPY_PORT env var)
      • mpfshell
        • open tty.SLAB_USBtoUART 
        • ls
      • rshell
        • ls -l
    • Connect and interact with a MicroPython board using a serial connection.
    • Connect with the Device REPL using a terminal. The baudrate of the REPL is 115200 (Data: 8 bit; Parity: None; Stop bits: 1 bit; Flow Control: None):
        • Windows:
          • Use Putty or any other terminal software.
        • Linux:
          • ToDo
        • MacOS:
          • miniterm.py /dev/tty.usbserial-1420 115200
      • Press Enter and the terminal should show Python prompt like >>>
    • Try a Hello World:
      • print("Hello World")
      • import esp
      • esp.flash_size()
      • import uos
      • uos.listdir()
    • Blink Example:
      • from machine import Pin
      • import utime as time
      • led_builtin = 2  # D4=gpio02
      • led = Pin(led_builtin, Pin.OUT)
      • while True:
        • led.on()
        • time.sleep(1)
        • led.off()
        • time.sleep(1)


    Additional Information:

    • You can use the Arduino IDE to upload your C/C++ software to the ESP boards, even after the upload of the MicroPython firmware. You don't need to upload the original Expressif default firmware to use the Arduino IDE. However, if you really wants to upload the Expressif firmware, then these as the instructions for reverting board to the original Expressif default firmware to use with arduino C/C++ language:




        • ESP8266_NONOS_SDK-master/bin/blank.bin  at  0x7E000 and 0x3E000
        • ESP8266_NONOS_SDK-master/bin/esp_init_data_default_v08.bin  at  0x7C000
        • ESP8266_NONOS_SDK-master/bin/boot_v1.7.bin  at  0x0
        • ESP8266_NONOS_SDK-master/bin/at/1024+1024/user1.2048.new.5.bin  at  0x1000
      • ESP32:
      • Choose the right COM port
      • Choose Baud Rate 460800
      • Click "Start" button.
    Tools:

    References: