From 6d48c9b8dfa0f9236f102954e6f0cbd58e2e3a4a Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 7 May 2019 19:49:54 +0200 Subject: [PATCH] Updated readme on some setup instruction, very WIP. --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/README.md b/README.md index f2b3fcb..6632072 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,68 @@ +# Setup + +I have used a Wemos D1 with ESP8266, the following will (per now) only describe setup with this chip, your mileage may vary. + - Find the chip over a serial connection + - Flashing micropython + - Transfere files to chip + - Add sensors + - (Elasticsearch) + - (Kibana dashboards) + +## Find the chip over a serial connection +The Wemos D1 uses a ch341 chip to convert our serial chip output to usb protocol. To get started download the CH341 chip driver here https://sparks.gogo.co.nz/ch340.html, or find another site with the driver. +After installed and rebooted the mac the chip should appear at "/dev/tty\*" after plugging the micro usb into your usb. As an example the output of `/dev/` shows me the following: +```bash +user@host: ls /dev/tty.* + +... +``` + +In my case the `/dev/tty.usbmodem1420` is the interface we want to connect to. Now we could connect directly to the chips serial connection we first want to flash the chip with microPython. + + - download link for microPython + - ampy download + - ampy commands + - getting info + - ampy flash +We will get back to transfering files with ampy in the next section. + + +Connecting to the serial interface: +This for me is the coolest part of builds like this. Connecting and interfacing with a chip over a interface communly used since the mid-80s. The easiest I found was to use `screen`. If your not familiar a quick guide can be found here: []. Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells). Each virtual terminal provides the functions of your normal terminal. This enables us to open a virtual terminal that displays what our microcontrollers prompt over the serial connection. + +```bash +screen /dev/tty.usbmodem1420 9600 +``` + - - - +The number at the end is the baud rate (it's a measure of symbol rate and is one of the components that determine the speed of communication over a data channel). + + +### Transfering files to the chip +We use ampy again with the following command: ` ` + +Some important behaviour: + - boot.py is called where we can setup e.g. sensors, pins and wifi. + - main.py is always called after boot is finished, this will most oftenly be the execution start of our program. +(More details can be found here) + +Tricks: + - os.listdir() + - machine.Timer use for timeouts without normal time package. + - ntptime to get universal time. Also our offset + + ### ntptime for universal time + We don't have a OS that handles setting the correct time based on the location. What we could use instead is the ntp protocol to fetch a time. Network Time Protocol (NTP) has been in operation since before 1985, and is one of the oldest Internet protocols in current use. This means it's most likely even going to be included in microPython. + + I needed to calculate a different offset to translate the ntp time to epoch (time since 1970). The offset I used was 946684800. Add this to your ntp time. E.g: + + ```python + NTP_OFFSET = 946684800 + ntpTime = ntptime.time() + epochTime = ntpTime + NTP_OFFSET + ``` + + + First prototype has a ESP8266[0][1] strapped on a soil moisture sensor [2]. The the small form factor, easily flash-able firware and gpio pins made the ESP8266 a great fit for the task. The main focus is the try transmit the soil moisture of a plant to an elasticsearch endpoint. Kibana is used to visialize the time since laste watered compared to the soil moisture. Using micropython to interface with the pins and it makes it easy to send json data to our elastic endpoint.