Skip to content

Commit f4c25ef

Browse files
author
AJ Keller
authored
Merge pull request #64 from aj-ptw/dev
Dev
2 parents 6152034 + cb2aea0 commit f4c25ef

File tree

7 files changed

+122
-71
lines changed

7 files changed

+122
-71
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ UPLOAD_PORT = /dev/ttyUSB0
4040
# BOARD = openbci
4141
BOARD = huzzah
4242
FLASH_DEF = 4M1M
43-
# F_CPU = 160000000l
43+
F_CPU = 80000000l
4444

4545

4646
#########################################

README.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ This document (the README file) is a hub to give you some information about the
2121
* [How can you get involved?](#get-involved)
2222
* [Get in touch](#contact-us)
2323
* [Find out more](#find-out-more)
24+
* [Installation](#install)
25+
* [Building](#build)
26+
* [Running](#running)
27+
* [License](#license)
2428

2529
## What are we doing?
2630

@@ -103,18 +107,7 @@ And of course, you'll want to know our:
103107

104108
Thank you so much (Danke schön! Merci beaucoup!) for visiting the project and we do hope that you'll join us on this amazing journey to make programming with OpenBCI fun and easy.
105109

106-
# Documentation
107-
108-
### Table of Contents:
109-
---
110-
111-
1. [Installation](#install)
112-
2. [Building](#build)
113-
3. [Running](#running)
114-
4. [License](#license)
115-
116-
117-
### <a name="install"></a> Installation:
110+
## <a name="install"></a> Installation:
118111

119112
Use the `DefaultWifiShield.ino` in examples.
120113

@@ -129,7 +122,7 @@ The ESP8266 runs arduino as well so there are several installs that need to happ
129122
The library we are interested in using is the [`SPISlave`](https://github.com/esp8266/Arduino/tree/master/libraries/SPISlave).
130123

131124

132-
### <a name="build"></a> Building and Flashing:
125+
## <a name="build"></a> Building and Flashing:
133126

134127
There are two steps to flashing code. Compiling the codebase, and then flashing it onto the wifi module.
135128
Makefiles make it a lot easier. Especially if you use [makeEspArduino](https://github.com/plerup/makeEspArduino). Follow the instructions from the project's github.
@@ -156,7 +149,7 @@ The `make` command runs the default commands from `makeEspArduino` with OpenBCI_
156149

157150
`make SKETCH=examples/WifiShieldJSON/WifiShieldJSON.ino UPLOAD_PORT=/dev/cu.usbserial-AI02BAAJ flash`
158151

159-
### <a name="running"></a> Running:
152+
## <a name="running"></a> Running:
160153

161154
There are two modes that the OpenBCI WiFi shield can run in
162155

changelog.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# v2.0.3
2+
3+
### Enhancements
4+
5+
* Reduce buffer size for better wifi manager
6+
* Fix LED flash when there are stored creds and shield attempts to connect
7+
* Add update wifi link to home page
8+
9+
### Work In Progress
10+
11+
* Hitting /wifi on some devices did not trigger wifi manager
12+
13+
### Third party
14+
15+
* Now building with v2.4.0 from ESP8266/Arduino
16+
117
# v2.0.2
218

319
* Reduce buffer size for better OTA Updates

examples/DefaultWifiShield/DefaultWifiShield.ino

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,28 @@ bool readRequest(WiFiClient& client) {
168168
return false;
169169
}
170170

171-
void requestWifiManager() {
171+
void requestWifiManagerStart() {
172172
#ifdef DEBUG
173173
debugPrintGet();
174-
Serial.println("requestWifiManager");
175174
#endif
176-
startWifiManager = true;
177175
sendHeadersForCORS();
178-
server.send(301, "text/html", "<meta http-equiv=\"refresh\" content=\"1; URL='/'\" />");
176+
// server.send(301, "text/html", "<meta http-equiv=\"refresh\" content=\"1; URL='/'\" />");
177+
178+
String out = "<!DOCTYPE html><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><html lang=\"en\"><h1 style=\"margin: auto\;width: 80%\;text-align: center\;\">Push The World</h1><br><p style=\"margin: auto\;width: 80%\;text-align: center\;\"><a href='http://";
179+
if (WiFi.localIP().toString().equals("192.168.4.1") || WiFi.localIP().toString().equals("0.0.0.0")) {
180+
out += "192.168.4.1";
181+
} else {
182+
out += WiFi.localIP().toString();
183+
}
184+
out += HTTP_ROUTE;
185+
out += "'>Click to Go To WiFi Manager</a></p><html>";
186+
server.send(200, "text/html", out);
187+
188+
ledFlashes = 5;
189+
ledInterval = 250;
190+
ledLastFlash = millis();
191+
192+
startWifiManager = true;
179193
}
180194

181195
JsonObject& getArgFromArgs(int args) {
@@ -500,24 +514,46 @@ void setup() {
500514
#ifdef DEBUG
501515
debugPrintGet();
502516
#endif
503-
String out = "<!DOCTYPE html><html lang=\"en\"><h1 style=\"margin: auto\;width: 50%\;text-align: center\;\">Push The World</h1><br><p style=\"margin: auto\;width: 50%\;text-align: center\;\"><a href='http://";
517+
String ip = "192.168.4.1";
518+
String out = "<!DOCTYPE html><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><html lang=\"en\"><h1 style=\"margin: auto\;width: 90%\;text-align: center\;\">Push The World</h1><br>";
504519
if (WiFi.localIP().toString().equals("192.168.4.1") || WiFi.localIP().toString().equals("0.0.0.0")) {
505520
if (WiFi.SSID().equals("")) {
521+
out += "<p style=\"margin: auto\;width: 80%\;text-align: center\;\"><a href='http://";
506522
out += "192.168.4.1";
507-
out += HTTP_ROUTE_WIFI;
508-
out += "'>Click to Configure Wifi</a></p><br>";
523+
out += HTTP_ROUTE_WIFI_CONFIG;
524+
out += "'>Click to Configure Wifi</a><br>If the above link does not work type 192.168.4.1/wifi in web browser and press Enter or Go.<br>See updates on issue <a href='https://github.com/OpenBCI/OpenBCI_WIFI/issues/62'>#62</a> on Github.</p><br>";
509525
} else {
526+
out += "<p style=\"margin: auto\;width: 80%\;text-align: center\;\"><a href='http://";
527+
out += "192.168.4.1";
528+
out += HTTP_ROUTE_WIFI_CONFIG;
529+
out += "'>Click to Configure Wifi</a><br>If the above link does not work type 192.168.4.1/wifi in web browser and press Enter or Go.<br>See updates on issue <a href='https://github.com/OpenBCI/OpenBCI_WIFI/issues/62'>#62</a> on Github.</p><br>";
530+
out += "<p style=\"margin: auto\;width: 80%\;text-align: center\;\"><a href='http://";
510531
out += "192.168.4.1";
511532
out += HTTP_ROUTE_WIFI_DELETE;
512533
out += "'>Click to Erase Wifi Credentials</a></p><br>";
513534
}
514535
} else {
536+
out += "<p style=\"margin: auto\;width: 80%\;text-align: center\;\"><a href='http://";
537+
out += WiFi.localIP().toString();
538+
out += HTTP_ROUTE_WIFI_CONFIG;
539+
out += "'>Click to Configure Wifi</a><br>If the above link does not work type ";
540+
out += WiFi.localIP().toString();
541+
out += "/wifi in web browser and press Enter or Go.<br>See updates on issue <a href='https://github.com/OpenBCI/OpenBCI_WIFI/issues/62'>#62</a> on Github.</p><br>";
542+
out += "<p style=\"margin: auto\;width: 80%\;text-align: center\;\"><a href='http://";
515543
out += WiFi.localIP().toString();
516544
out += HTTP_ROUTE_WIFI_DELETE;
517545
out += "'>Click to Erase Wifi Credentials</a></p><br>";
518546
}
519-
out += "<p style=\"margin: auto\;width: 50%\;text-align: center\;\"> Please visit <a href='https://app.swaggerhub.com/apis/pushtheworld/openbci-wifi-server/2.0.0'>Swaggerhub</a> for the latest HTTP endpoints</p><br>";
520-
out += "<p style=\"margin: auto\;width: 50%\;text-align: center\;\"> Shield Firmware: " + String(SOFTWARE_VERSION) + "</p></html>";
547+
out += "<p style=\"margin: auto\;width: 80%\;text-align: center\;\"><a href='http://";
548+
if (WiFi.localIP().toString().equals("192.168.4.1") || WiFi.localIP().toString().equals("0.0.0.0")) {
549+
out += "192.168.4.1/update";
550+
} else {
551+
out += WiFi.localIP().toString();
552+
out += "/update";
553+
}
554+
out += "'>Click to Update WiFi Firmware</a></p><br>";
555+
out += "<p style=\"margin: auto\;width: 80%\;text-align: center\;\"> Please visit <a href='https://app.swaggerhub.com/apis/pushtheworld/openbci-wifi-server/2.0.0'>Swaggerhub</a> for the latest HTTP endpoints</p><br>";
556+
out += "<p style=\"margin: auto\;width: 80%\;text-align: center\;\"> Shield Firmware: " + String(SOFTWARE_VERSION) + "</p></html>";
521557

522558
server.send(200, "text/html", out);
523559
});
@@ -657,7 +693,7 @@ void setup() {
657693
});
658694
server.on(HTTP_ROUTE_BOARD, HTTP_OPTIONS, sendHeadersForOptions);
659695

660-
server.on(HTTP_ROUTE_WIFI, HTTP_GET, requestWifiManager);
696+
server.on(HTTP_ROUTE_WIFI, HTTP_GET, requestWifiManagerStart);
661697
server.on(HTTP_ROUTE_WIFI, HTTP_DELETE, []() {
662698
#ifdef DEBUG
663699
debugPrintDelete();
@@ -667,7 +703,7 @@ void setup() {
667703
});
668704
server.on(HTTP_ROUTE_WIFI, HTTP_OPTIONS, sendHeadersForOptions);
669705

670-
server.on(HTTP_ROUTE_WIFI_CONFIG, HTTP_GET, requestWifiManager);
706+
server.on(HTTP_ROUTE_WIFI_CONFIG, HTTP_GET, requestWifiManagerStart);
671707
server.on(HTTP_ROUTE_WIFI_CONFIG, HTTP_OPTIONS, sendHeadersForOptions);
672708

673709
server.on(HTTP_ROUTE_WIFI_DELETE, HTTP_GET, []() {
@@ -699,8 +735,9 @@ void setup() {
699735
ledState = false;
700736
// digitalWrite(LED_NOTIFY, HIGH);
701737
} else {
702-
ledFlashes = 2;
703-
ledInterval = 500;
738+
ledState = false;
739+
ledFlashes = 4;
740+
ledInterval = 250;
704741
wifiConnectTimeout = millis();
705742
tryConnectToAP = true;
706743
#ifdef DEBUG
@@ -754,10 +791,14 @@ void loop() {
754791
httpUpdater.setup(&server);
755792
server.begin();
756793
MDNS.addService("http", "tcp", 80);
757-
digitalWrite(LED_NOTIFY, HIGH);
794+
// digitalWrite(LED_NOTIFY, HIGH);
758795
#ifdef DEBUG
759796
Serial.println("Connected to network, switching to station mode.");
760797
#endif
798+
ledState = false;
799+
ledFlashes = 2;
800+
ledInterval = 500;
801+
ledLastFlash = millis();
761802
} else if (millis() > (wifiConnectTimeout + 10000)) {
762803
#ifdef DEBUG
763804
Serial.printf("Failed to connect to network with %d bytes on head\n", ESP.getFreeHeap());
@@ -824,12 +865,6 @@ void loop() {
824865
Serial.printf("Failed to connect with WiFi Manager with %d bytes on heap\n" , ESP.getFreeHeap());
825866
}
826867
#endif
827-
828-
#ifdef DEBUG
829-
Serial.println("Calling restart");
830-
#endif
831-
// wifiReset = true;
832-
// ESP.restart();
833868
}
834869

835870
int packetsToSend = wifi.rawBufferHead - wifi.rawBufferTail;

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=OpenBCI_Wifi
2-
version=2.0.2
2+
version=2.0.3
33
author=AJ Keller <pushtheworldllc@gmail.com>
44
maintainer=AJ Keller <pushtheworldllc@gmail.com>
55
sentence=The core of the OpenBCI Wifi Shield.

src/OpenBCI_Wifi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ String OpenBCI_Wifi_Class::getOutputProtocolString(OUTPUT_PROTOCOL outputProtoco
462462
return OUTPUT_NONE;
463463
}
464464
}
465-
465+
#ifdef RAW_TO_JSON
466466
double OpenBCI_Wifi_Class::getScaleFactorVoltsGanglion() {
467467
return MCP_SCALE_FACTOR_VOLTS;
468468
}
@@ -494,6 +494,7 @@ double OpenBCI_Wifi_Class::getScaleFactorVoltsCyton(uint8_t gain) {
494494
return 1.0;
495495
}
496496
}
497+
#endif
497498

498499
/**
499500
* Used to print out a long long number

src/OpenBCI_Wifi_Definitions.h

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,52 @@
99
#ifndef __OpenBCI_Wifi_Definitions__
1010
#define __OpenBCI_Wifi_Definitions__
1111

12-
#define SOFTWARE_VERSION "v2.0.2"
12+
#define SOFTWARE_VERSION "v2.0.3"
1313

14-
#define ADS1299_VREF 4.5
15-
#define MCP3912_VREF 1.2
16-
#define ADC_24BIT_RES 8388607.0
17-
#define ADC_24BIT_MAX_VAL_NANO_VOLT 8388607000000000.0
18-
#define BYTES_PER_SPI_PACKET 32
19-
#define BYTES_PER_OBCI_PACKET 33
2014
// #define DEBUG 1
21-
#define MAX_SRV_CLIENTS 2
22-
#define BYTES_PER_CHANNEL 3
15+
2316
#ifdef RAW_TO_JSON
17+
#define ADS1299_VREF 4.5
18+
19+
#define ADC_24BIT_RES 8388607.0
20+
#define ADC_24BIT_MAX_VAL_NANO_VOLT 8388607000000000.0
21+
22+
#define ADS_GAIN_1 1
23+
#define ADS_GAIN_2 2
24+
#define ADS_GAIN_4 4
25+
#define ADS_GAIN_6 6
26+
#define ADS_GAIN_8 8
27+
#define ADS_GAIN_12 12
28+
#define ADS_GAIN_24 24
29+
30+
#define ADS_SCALE_FACTOR_VOLTS_1 0.000000536441867
31+
#define ADS_SCALE_FACTOR_VOLTS_2 0.000000268220934
32+
#define ADS_SCALE_FACTOR_VOLTS_4 0.000000134110467
33+
#define ADS_SCALE_FACTOR_VOLTS_6 0.000000089406978
34+
#define ADS_SCALE_FACTOR_VOLTS_8 0.000000067055233
35+
#define ADS_SCALE_FACTOR_VOLTS_12 0.000000044703489
36+
#define ADS_SCALE_FACTOR_VOLTS_24 0.000000022351744
37+
38+
#define ARDUINOJSON_USE_LONG_LONG 1
39+
#define ARDUINOJSON_ADDITIONAL_BYTES_4_CHAN 115
40+
#define ARDUINOJSON_ADDITIONAL_BYTES_8_CHAN 195
41+
#define ARDUINOJSON_ADDITIONAL_BYTES_16_CHAN 355
42+
#define ARDUINOJSON_ADDITIONAL_BYTES_24_CHAN 515
43+
#define ARDUINOJSON_ADDITIONAL_BYTES_32_CHAN 675
44+
45+
#define GANGLION_GAIN 51
46+
47+
#define MCP_SCALE_FACTOR_VOLTS 0.00000000186995
48+
#define MCP3912_VREF 1.2
2449
#define NUM_PACKETS_IN_RING_BUFFER_JSON 28
2550
#define NUM_PACKETS_IN_RING_BUFFER_RAW 1
2651
#else
27-
#define NUM_PACKETS_IN_RING_BUFFER_RAW 250
52+
#define NUM_PACKETS_IN_RING_BUFFER_RAW 200
2853
#define MAX_PACKETS_PER_SEND_TCP 42
2954
#endif
55+
#define BYTES_PER_SPI_PACKET 32
56+
#define BYTES_PER_OBCI_PACKET 33
57+
#define BYTES_PER_CHANNEL 3
3058
#define WIFI_SPI_MSG_LAST 0x01
3159
#define WIFI_SPI_MSG_MULTI 0x02
3260
#define WIFI_SPI_MSG_GAINS 0x03
@@ -37,20 +65,14 @@
3765
#define NUM_CHANNELS_GANGLION 4
3866
#define LED_PROG 0
3967
#define LED_NOTIFY 5
40-
#define GANGLION_GAIN 51
4168
#define DEFAULT_LATENCY 10000
4269
#define DEFAULT_MQTT_PORT 1883
4370
// #define bit(b) (1UL << (b)) // Taken directly from Arduino.h
4471
// Arduino JSON needs bytes for duplication
4572
// to recalculate visit:
4673
// https://bblanchon.github.io/ArduinoJson/assistant/index.html
4774
// #define ARDUINOJSON_USE_DOUBLE 1
48-
#define ARDUINOJSON_USE_LONG_LONG 1
49-
#define ARDUINOJSON_ADDITIONAL_BYTES_4_CHAN 115
50-
#define ARDUINOJSON_ADDITIONAL_BYTES_8_CHAN 195
51-
#define ARDUINOJSON_ADDITIONAL_BYTES_16_CHAN 355
52-
#define ARDUINOJSON_ADDITIONAL_BYTES_24_CHAN 515
53-
#define ARDUINOJSON_ADDITIONAL_BYTES_32_CHAN 675
75+
5476
#define MICROS_IN_SECONDS 1000000
5577
#define SPI_MASTER_POLL_TIMEOUT_MS 100
5678
#define SPI_TIMEOUT_CLIENT_RESPONSE 400
@@ -60,23 +82,7 @@
6082
#define NANO_VOLTS_IN_VOLTS 1000000000.0
6183
#define MAX_JSON_BUFFER_SIZE 4000
6284

63-
#define ADS_GAIN_1 1
64-
#define ADS_GAIN_2 2
65-
#define ADS_GAIN_4 4
66-
#define ADS_GAIN_6 6
67-
#define ADS_GAIN_8 8
68-
#define ADS_GAIN_12 12
69-
#define ADS_GAIN_24 24
70-
71-
#define ADS_SCALE_FACTOR_VOLTS_1 0.000000536441867
72-
#define ADS_SCALE_FACTOR_VOLTS_2 0.000000268220934
73-
#define ADS_SCALE_FACTOR_VOLTS_4 0.000000134110467
74-
#define ADS_SCALE_FACTOR_VOLTS_6 0.000000089406978
75-
#define ADS_SCALE_FACTOR_VOLTS_8 0.000000067055233
76-
#define ADS_SCALE_FACTOR_VOLTS_12 0.000000044703489
77-
#define ADS_SCALE_FACTOR_VOLTS_24 0.000000022351744
78-
79-
#define MCP_SCALE_FACTOR_VOLTS 0.00000000186995
85+
8086

8187
#define BOARD_TYPE_CYTON "cyton"
8288
#define BOARD_TYPE_CYTON_DAISY "daisy"

0 commit comments

Comments
 (0)