Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #10

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ The development server serves everything at `http://localhost:8774`.

Depending on when your bttn was built, it may have shipped with an older Wi-Fi module firmware. It's recommended to upgrade this firmware, and the process is stable and safe, but as with all things, your mileage may vary.

As of this writing, version 3.5.3 is available and brings many improvements over older versions.
As of this writing, version 3.6 is available and brings many improvements over older versions. See `ReleaseNotes.pdf` for each firmware version to see what improvements have been made.

#### Updating the Wi-Fi module

Expand All @@ -269,12 +269,12 @@ Download the latest Wi-Fi module firmware from [here](https://my.st.com/content/
Unzip it and locate the module firmware version you wish to use.

For our example, we've chosen:
> SPWF01S-170111-665d284-RELEASE-main.ota
> SPWF01S-180621-5f9a5a0-RELEASE-main.ota

Move the firmware into the `ota` folder:

```console
$ mv ~/Downloads/STSW-WIFI001/Rel.\ 3.5.3/OTA/SPWF01S-170111-665d284-RELEASE-main.ota public/ota/
$ mv ~/Downloads/STSW-WIFI001/Rel.\ 3.6/OTA/SPWF01S-180621-5f9a5a0-RELEASE-main.ota public/ota/
```

Run the included web server (more on this in [Development server](#development-server)):
Expand Down
17 changes: 14 additions & 3 deletions cmd/openbttn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func otaHandler(otaPath string) func(w http.ResponseWriter, r *http.Request) {
n, err := f.Read(b)
if err == io.EOF {
keepGoing = false
if n == 0 {
break
}
} else if err != nil {
panic(err)
}
Expand All @@ -149,12 +152,20 @@ func otaHandler(otaPath string) func(w http.ResponseWriter, r *http.Request) {
io.CopyN(w, content, int64(n))
numBytes += n

// Pause 300 ms between chunks to give more
log.Printf("Sent %d/%s OTA bytes in %v", numBytes, size, time.Now().Sub(start))

// Pause a bit between chunks to give some
// time for the module to store each chunk.
time.Sleep(300 * time.Millisecond)
delay := 300 * time.Millisecond
select {
case <-r.Context().Done():
log.Printf("Client disconnected, sent %d/%s OTA bytes in %v", numBytes, size, time.Now().Sub(start))
return
case <-time.After(delay):
}
}

log.Printf("Sent %d/%s OTA bytes in %v", numBytes, size, time.Now().Sub(start))
log.Println("OTA complete!")
}
}

Expand Down
2 changes: 1 addition & 1 deletion libopencm3
Submodule libopencm3 updated 540 files
2 changes: 1 addition & 1 deletion public/openbttn/firstset.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h2>Firmware Upgrade (SPWF01SA)</h2>
<table>
<tr>
<td>URL:</td>
<td><input type="url" id="ota" value="http://192.168.1.2:8774/ota/SPWF01S-160129-c5bf5ce-RELEASE-main.ota" size="60"></td>
<td><input type="url" id="ota" value="http://192.168.1.2:8774/ota/SPWF01S-180621-5f9a5a0-RELEASE-main.ota" size="60"></td>
</tr>
<tr>
<td></td>
Expand Down
2 changes: 1 addition & 1 deletion public/openbttn/firstset.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function getFirmwareVersion(data) {
function checkFirmwareVersion({ date, commit }) {
if (date < 141106) {
document.getElementById('fw-form').innerHTML = '<p class="warn">Firmware is too old for OTA update.</p>';
} else if (date < 170111) {
} else if (date < 180621) {
document.getElementById('fw').classList.remove('hidden');
}
document.getElementById('fw-ver').textContent = date + '-' + commit;
Expand Down
35 changes: 25 additions & 10 deletions public/openbttn/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,44 @@ path=($SCRIPT/node_modules/.bin $path)
done

print

data_c=''
data_h_size=''
data_h_extern=''
for html in *.html; do
gzip -9 $html
xxd -i $html.gz > $html.xxd
grep -v "^unsigned int" $html.xxd >> $html.c

name=$(head -n1 $html.c)
name=${(j..)${(Cs._.)${${name#unsigned char }%\[*}}}
name="const uint8_t g_Data${name}[] = {"
{ print $name; tail -n +2 $html.c } >> data.c
name="const uint8_t g_Data${name}[]"
data_c+="$(print "$name = {"; tail -n +2 $html.c)"$'\n'
data_h_extern+="extern ${name};"$'\n'

size=$(grep "^unsigned int" $html.xxd)
sizeNum=${${size#*\= }%;}
size=${(U)${${size#unsigned int }%_len \=*}}
size="#define DATA_${size}_LENGTH ${sizeNum}"
print $size >> data.h
data_h_size+="#define DATA_${size}_LENGTH ${sizeNum}"$'\n'
done

{
cat data.h
cat data.c
} | pbcopy
pbpaste
)
cat <<EOF > $SCRIPT/../../src/data.c
#include <stdint.h>

#include "data.h"

${data_c}
EOF
cat <<EOF > $SCRIPT/../../src/data.h
#ifndef DATA_H
#define DATA_H

#include <stdint.h>

${data_h_size}
${data_h_extern}
#endif /* DATA_H */
EOF
)

rm -r $TMP
5 changes: 4 additions & 1 deletion public/openbttn/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"devDependencies": {
"html-inline": "^1.2.0",
"html-minifier": "^3.1.0",
"html-minifier": "^3.5.20",
"uglify-js": "github:mishoo/UglifyJS2#harmony"
},
"dependencies": {
"uglify-es": "github:mishoo/UglifyJS2#harmony"
}
}
Loading