Skip to content

Commit

Permalink
readme added, flash script extended
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwe committed Nov 26, 2016
1 parent 0ba0724 commit 579f81c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 11 deletions.
60 changes: 60 additions & 0 deletions utils/flash/README.md
@@ -0,0 +1,60 @@
# Flash script for Linux

[Here](https://github.com/opendata-stuttgart/sensors-software/tree/master/utils/flash) you find a tool for flashing an ESP8266 with the most recent firmware release of the fine dust measuring station.

The script asks some more info, which is required by the admins to let the sensors data into the database.
Usally, the device should be available on `/dev/ttyUSB0` (if you have no other usb2serial attached).
The script makes use of two tools, both named esptool(.py):

* one comes with the ESP8266 plugin for the the Android development IDE https://github.com/esp8266/arduino-esp8266fs-plugin
* the other is a python script from https://github.com/themadinventor/esptool

The script tries to find them in standard paths. You can set variables to point to them.

## transcript of a flash session with the script (2016-11-26)

export gitlocation=/path/to/gitrepoparent # change path here, or just cd into the right location
cd $gitlocation/sensors-software/utils/flash
./flashlatest.sh

usage: [esptool=/path/to/esptool] [esptoolpy=/path/to/esptool.py] [devserial=/dev/ttyUSB0] ./flashlatest.sh
writes output to listofflashed.csv
devserial=/dev/ttyUSB0 # define to change

ask more infos? [Y/n]Y
PM sensor revision (on back/flat side top left corner)? [default: ]V2-006
PM sensor serial number (SN on sticker, besides fan, below barcode)? [default: ]5000-C537
Adress? [like: 70000 Stuttgart, Staubweg 00]70000 Stuttgart, Staubweg 00
Email? [like: unknown@example.com]
latitude? [like: 00.0000]48.000
longitude? [like: 00.0000]9.000
DBID esp8266-2331040 0x002391a0 5c:cf:7f:23:91:a0 V2-006:5000-C537 @ 48.000 9.000 70000 Stuttgart, Staubweg 00 SID1 SNAME1 SID2 SNAME2
patch Freifunk to XXXXXXXX? [y/N] N
--2016-11-26 18:19:28-- https://www.madavi.de/sensor/update/data/latest.bin
Auflösen des Hostnamen »www.madavi.de (www.madavi.de)«... 2a01:238:4202:e00:342a:970a:ad33:75fd, 85.214.240.94
Verbindungsaufbau zu www.madavi.de (www.madavi.de)|2a01:238:4202:e00:342a:970a:ad33:75fd|:443... verbunden.
HTTP-Anforderung gesendet, warte auf Antwort... 416 Requested Range Not Satisfiable

Download der Datei schon vollständig; kein Download notwendig.
flash now? [y/N] y
esptool v0.4.9 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
setting board to nodemcu
[...]
writing flash
[...]
................................................................................ [ 90% ]
........................................ [ 100% ]
starting app without reboot
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
espcomm_send_command: receiving 2 bytes of data
closing bootloader
to erase SPIFF (config data) use arduino IDE and https://github.com/esp8266/arduino-esp8266fs-plugin
see https://github.com/esp8266/arduino-esp8266fs-plugin

to erase SPIFF (config data) use arduino IDE and https://github.com/esp8266/arduino-esp8266fs-plugin
see https://github.com/esp8266/arduino-esp8266fs-plugin
or overwrite SPIFFS now? [y/N] N

Now the information about your sensor is added at the end of file listofflashed.csv

40 changes: 29 additions & 11 deletions utils/flash/flashlatest.sh
@@ -1,7 +1,7 @@
#!/bin/bash

outappendfile=listofflashed.csv
echo "usage: [esptool=/path/to/esptool] [esptoolpy=/path/to/esptool.py] $0"
echo "usage: [esptool=/path/to/esptool] [esptoolpy=/path/to/esptool.py] [devserial=/dev/ttyUSB0] $0"
echo "writes output to $outappendfile"

if [ -z "$esptool" ] ; then
Expand All @@ -15,23 +15,35 @@ fi
if [ -z "$esptoolpy" ] ; then
esptoolpy="$(which esptool.py)"
if [ -z "$esptoolpy" ] ; then
echo esptool.py not found, please define esptoolpy="/path/to/esptool.py"
echo esptool.py not found in PATH, please define esptoolpy="/path/to/esptool.py"
echo "https://github.com/themadinventor/esptool"
exit 1
fi
fi

if [ -z "$devserial" ] ; then
devserial=/dev/ttyUSB0
echo devserial="$devserial" \# define to change
fi
if [ ! -w "$devserial" ] ; then
echo "no write access to $devserial"
read -p "list all serial devices? [Y/n]" ans
if [ "$ans" != "n" ] ; then
ls -l /dev/serial/by-id/
fi
exit 1
fi


if [ ! -f "$outappendfile" ] ; then
echo "sensorID sensorname hexchipID MAC shortname email lat lon locationaddress sensorID1 sensorname1 sensorID2 sensorname2" >> "$outappendfile"
echo "sensorID sensorname hexchipID MAC revision:serial email lat lon locationaddress sensorID1 sensorname1 sensorID2 sensorname2" >> "$outappendfile"
fi

# get info
chipid="$($esptoolpy chip_id)"
chid=$($esptoolpy chip_id| grep -io '0x[0-9a-fA-F]*\b')
chiddec=$(python -c "print (\"%d\"%($chid))")
mac="$($esptoolpy read_mac| grep -io '[0-9a-f:]\{17\}')"
shortname="$chiddec"
locadr="LOCADRESS"
email="@"
lat="LAT"
Expand All @@ -41,11 +53,17 @@ echo ""
read -p "ask more infos? [Y/n]" ans

if [ "$ans" != "n" ] ; then

read -p "Station shortname? [default: $shortname]" ans
examplestr="V0-000"
read -p "PM sensor revision (on back/flat side top left corner)? [default: $examplestring]" ans
if [ -n "$ans" ] ; then
shortname="$ans"
srevision="$ans"
fi
examplestr="0000-0000"
read -p "PM sensor serial number (SN on sticker, besides fan, below barcode)? [default: $examplestring]" ans
if [ -n "$ans" ] ; then
sserial="$ans"
fi

examplestr="70000 Stuttgart, Staubweg 00"
read -p "Adress? [like: $examplestr]" ans
if [ -n "$ans" ] ; then
Expand All @@ -68,11 +86,10 @@ if [ "$ans" != "n" ] ; then
fi
fi

info="DBID\tesp8266-$chiddec\t$chid\t$mac\t$shortname\t$email\t$lat\t$lon\t$locadr\tSID1\tSNAME1\tSID2\tSNAME2"
info="DBID\tesp8266-$chiddec\t$chid\t$mac\t$srevision:$sserial\t$email\t$lat\t$lon\t$locadr\tSID1\tSNAME1\tSID2\tSNAME2"
echo -e "$info" | tee -a "$outappendfile"



#esptool.py write_flash -vv -cb 57600 -ca 0x00000 -cp /dev/ttyUSB0 -cf latest.bin

read -p "patch Freifunk to XXXXXXXX? [y/N] " ans
Expand All @@ -94,7 +111,7 @@ fi
read -p "flash now? [y/N] " ans
if [ "$ans" == "y" ]
then
$esptool -vv -cd nodemcu -cb 57600 -ca 0x00000 -cp /dev/ttyUSB0 -cf "$binfile"
$esptool -vv -cd nodemcu -cb 57600 -ca 0x00000 -cp "$devserial" -cf "$binfile"
fi


Expand All @@ -119,5 +136,6 @@ if [ "$ans" == "y" ] ; then
bunzip2 -k "${spiffbin}.bz2"
fi

$esptool -vv -cd nodemcu -cb 115200 -ca 0x100000 -cp /dev/ttyUSB0 -cf "$spiffbin"
$esptool -vv -cd nodemcu -cb 115200 -ca 0x100000 -cp "$devserial" -cf "$spiffbin"
fi

0 comments on commit 579f81c

Please sign in to comment.