Skip to content

Commit 0310d33

Browse files
authored
Support ESP32 (#208)
1 parent c840ab8 commit 0310d33

File tree

20 files changed

+145
-58
lines changed

20 files changed

+145
-58
lines changed

.github/workflows/main.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ jobs:
1616
- examples/AstronomyDemo
1717
- examples/OpenWeatherMapCurrentDemo
1818
- examples/OpenWeatherMapForecastDemo
19-
# doesn't work on ESP32 due to WiFi Manager dependency
20-
- examples/PlaneSpotterDemo
19+
# - examples/PlaneSpotterDemo doesn't work on ESP32 due to WiFi Manager dependency
2120
- examples/SunMoonCalcDemo
2221
- examples/WeatherStationDemo
2322
- examples/WorldClockDemo
@@ -43,6 +42,6 @@ jobs:
4342
- name: Install library dependencies
4443
run: pio lib -g install "JsonStreamingParser" "thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0" "WifiManager@>=0.15.0-beta"
4544
- name: Run PlatformIO
46-
run: pio ci --lib="." --project-option="lib_deps=JsonStreamingParser" --board=nodemcuv2 --board=d1_mini
45+
run: pio ci --lib="." --project-option="lib_deps=JsonStreamingParser" --board=nodemcuv2 --board=d1_mini --board=esp-wrover-kit
4746
env:
4847
PLATFORMIO_CI_SRC: ${{ matrix.example }}

examples/AerisForecastsDemo/AerisForecastsDemo.ino

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ SOFTWARE.
2323

2424
#include <Arduino.h>
2525

26+
#if defined(ESP8266)
2627
#include <ESP8266WiFi.h>
28+
#else
29+
#include <WiFi.h>
30+
#endif
2731
#include <JsonListener.h>
2832
#include "AerisForecasts.h"
2933

@@ -40,7 +44,11 @@ String AERIS_LOCATION = "Zurich,CH";
4044
/**
4145
* WiFi Settings
4246
*/
47+
#if defined(ESP8266)
4348
const char* ESP_HOST_NAME = "esp-" + ESP.getFlashChipId();
49+
#else
50+
const char* ESP_HOST_NAME = "esp-" + ESP.getEfuseMac();
51+
#endif
4452
const char* WIFI_SSID = "yourssid";
4553
const char* WIFI_PASSWORD = "yourpassw0rd";
4654

@@ -63,7 +71,7 @@ void print(String name, uint16_t value) {
6371
Serial.printf("%s: %d\n", name.c_str(), value);
6472
}
6573

66-
void print(String name, sint16_t value) {
74+
void print(String name, int16_t value) {
6775
Serial.printf("%s: %d\n", name.c_str(), value);
6876
}
6977

examples/AerisObservationDemo/AerisObservationDemo.ino

+8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ SOFTWARE.
2323

2424
#include <Arduino.h>
2525

26+
#if defined(ESP8266)
2627
#include <ESP8266WiFi.h>
28+
#else
29+
#include <WiFi.h>
30+
#endif
2731
#include <JsonListener.h>
2832
#include "AerisObservations.h"
2933

@@ -41,7 +45,11 @@ String AERIS_LOCATION = "Zurich,CH";
4145
/**
4246
* WiFi Settings
4347
*/
48+
#if defined(ESP8266)
4449
const char* ESP_HOST_NAME = "esp-" + ESP.getFlashChipId();
50+
#else
51+
const char* ESP_HOST_NAME = "esp-" + ESP.getEfuseMac();
52+
#endif
4553
const char* WIFI_SSID = "yourssid";
4654
const char* WIFI_PASSWORD = "yourpassw0rd";
4755

examples/AerisSunMoonDemo/AerisSunMoonDemo.ino

+8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ SOFTWARE.
2323

2424
#include <Arduino.h>
2525

26+
#if defined(ESP8266)
2627
#include <ESP8266WiFi.h>
28+
#else
29+
#include <WiFi.h>
30+
#endif
2731
#include <JsonListener.h>
2832
#include "AerisSunMoon.h"
2933

@@ -41,7 +45,11 @@ String AERIS_LOCATION = "Zurich,CH";
4145
/**
4246
* WiFi Settings
4347
*/
48+
#if defined(ESP8266)
4449
const char* ESP_HOST_NAME = "esp-" + ESP.getFlashChipId();
50+
#else
51+
const char* ESP_HOST_NAME = "esp-" + ESP.getEfuseMac();
52+
#endif
4553
const char* WIFI_SSID = "yourssid";
4654
const char* WIFI_PASSWORD = "yourpassw0rd";
4755

examples/AstronomyDemo/AstronomyDemo.ino

+4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ See more at https://thingpulse.com
2424
*/
2525

2626
#include <Arduino.h>
27+
#if defined(ESP8266)
2728
#include <ESP8266WiFi.h>
29+
#else
30+
#include <WiFi.h>
31+
#endif
2832
#include <ESPHTTPClient.h>
2933
#include <time.h>
3034
#include "Astronomy.h"

examples/OpenWeatherMapCurrentDemo/OpenWeatherMapCurrentDemo.ino

+8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ SOFTWARE.
2323

2424
#include <Arduino.h>
2525

26+
#if defined(ESP8266)
2627
#include <ESP8266WiFi.h>
28+
#else
29+
#include <WiFi.h>
30+
#endif
2731
#include <JsonListener.h>
2832
#include <time.h>
2933
#include "OpenWeatherMapCurrent.h"
@@ -56,7 +60,11 @@ boolean IS_METRIC = true;
5660
/**
5761
* WiFi Settings
5862
*/
63+
#if defined(ESP8266)
5964
const char* ESP_HOST_NAME = "esp-" + ESP.getFlashChipId();
65+
#else
66+
const char* ESP_HOST_NAME = "esp-" + ESP.getEfuseMac();
67+
#endif
6068
const char* WIFI_SSID = "yourssid";
6169
const char* WIFI_PASSWORD = "yourpassw0rd";
6270

examples/OpenWeatherMapForecastDemo/OpenWeatherMapForecastDemo.ino

+8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ SOFTWARE.
2323

2424
#include <Arduino.h>
2525

26+
#if defined(ESP8266)
2627
#include <ESP8266WiFi.h>
28+
#else
29+
#include <WiFi.h>
30+
#endif
2731
#include <JsonListener.h>
2832
#include <time.h>
2933
#include "OpenWeatherMapForecast.h"
@@ -57,7 +61,11 @@ uint8_t MAX_FORECASTS = 15;
5761
/**
5862
* WiFi Settings
5963
*/
64+
#if defined(ESP8266)
6065
const char* ESP_HOST_NAME = "esp-" + ESP.getFlashChipId();
66+
#else
67+
const char* ESP_HOST_NAME = "esp-" + ESP.getEfuseMac();
68+
#endif
6169
const char* WIFI_SSID = "yourssid";
6270
const char* WIFI_PASSWORD = "yourpassw0rd";
6371

examples/OpenWeatherMapOneCallDemo/OpenWeatherMapOneCallDemo.ino

+8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ SOFTWARE.
2323

2424
#include <Arduino.h>
2525

26+
#if defined(ESP8266)
2627
#include <ESP8266WiFi.h>
28+
#else
29+
#include <WiFi.h>
30+
#endif
2731
#include <JsonListener.h>
2832
#include <time.h>
2933
#include "OpenWeatherMapOneCall.h"
@@ -52,7 +56,11 @@ boolean IS_METRIC = false;
5256
/**
5357
* WiFi Settings
5458
*/
59+
#if defined(ESP8266)
5560
const char* ESP_HOST_NAME = "esp-" + ESP.getFlashChipId();
61+
#else
62+
const char* ESP_HOST_NAME = "esp-" + ESP.getEfuseMac();
63+
#endif
5664
const char* WIFI_SSID = "yourssid";
5765
const char* WIFI_PASSWORD = "yourpassw0rd";
5866

examples/PlaneSpotterDemo/PlaneSpotterDemo.ino

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ SOFTWARE.
2323
See more at https://thingpulse.com
2424
*/
2525
#include <Arduino.h>
26+
#if defined(ESP8266)
2627
#include <ESP8266WiFi.h>
28+
#include <ESP8266mDNS.h>
29+
#else
30+
#include <WiFi.h>
31+
#include <ESPmDNS.h>
32+
#include <WiFiUdp.h>
33+
#endif
2734
#include <ESPHTTPClient.h>
2835
#include <Ticker.h>
2936
#include <JsonListener.h>
3037
#include <ArduinoOTA.h>
31-
#include <ESP8266mDNS.h>
3238

3339
#include <DNSServer.h>
3440
#include <ESP8266WebServer.h>

examples/SunMoonCalcDemo/SunMoonCalcDemo.ino

+4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ SOFTWARE.
2222
*/
2323

2424
#include <Arduino.h>
25+
#if defined(ESP8266)
2526
#include <ESP8266WiFi.h>
27+
#else
28+
#include <WiFi.h>
29+
#endif
2630
#include <ESPHTTPClient.h>
2731
#include <time.h>
2832
#include "SunMoonCalc.h"

examples/WeatherStationDemo/WeatherStationDemo.ino

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ See more at https://thingpulse.com
2525

2626
#include <Arduino.h>
2727

28-
#include <ESPWiFi.h>
28+
#if defined(ESP8266)
29+
#include <ESP8266WiFi.h>
30+
#include <coredecls.h> // settimeofday_cb()
31+
#else
32+
#include <WiFi.h>
33+
#endif
2934
#include <ESPHTTPClient.h>
3035
#include <JsonListener.h>
3136

3237
// time
3338
#include <time.h> // time() ctime()
3439
#include <sys/time.h> // struct timeval
35-
#include <coredecls.h> // settimeofday_cb()
3640

3741
#include "SSD1306Wire.h"
3842
#include "OLEDDisplayUi.h"

examples/WorldClockDemo/WorldClockDemo.ino

+8-10
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ See more at https://thingpulse.com
2525

2626
#include <Arduino.h>
2727

28+
#if defined(ESP8266)
2829
#include <ESP8266WiFi.h>
29-
#include <ESP8266HTTPClient.h>
30+
#else
31+
#include <WiFi.h>
32+
#endif
33+
#include <ESPHTTPClient.h>
3034
#include <Ticker.h>
3135
#include <JsonListener.h>
3236
#include <SSD1306Wire.h>
@@ -50,16 +54,10 @@ const int UPDATE_INTERVAL_SECS = 10 * 60; // Update every 10 minutes
5054

5155
// Display Settings
5256
const int I2C_DISPLAY_ADDRESS = 0x3c;
53-
const int SDA_PIN = D3;
54-
const int SDC_PIN = D4;
57+
const int SDA_PIN = SDA;
58+
const int SCL_PIN = SCL;
5559

56-
// TimeClient settings
57-
58-
59-
// Initialize the oled display for address 0x3c
60-
// sda-pin=14 and sdc-pin=12
61-
62-
SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);
60+
SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SCL_PIN);
6361
OLEDDisplayUi ui ( &display );
6462

6563
/***************************

src/AerisForecasts.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ void AerisForecasts::doUpdate(AerisForecastData *forecasts, String path, uint8_t
4545
Serial.printf("[HTTP] Requesting resource at http://%s:%u%s\n", host.c_str(), port, path.c_str());
4646

4747
WiFiClient client;
48-
if(client.connect(host, port)) {
48+
#if defined(ESP8266)
49+
if (client.connect(host, port)) {
50+
#else
51+
if (client.connect(host.c_str(), port)) {
52+
#endif
4953
bool isBody = false;
5054
char c;
5155
Serial.println("[HTTP] connected, now GETting data");

src/AerisForecasts.h

+26-26
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ typedef struct AerisForecastData {
3030
uint64_t timestamp; // 1526706000
3131
String validTime; // "2018-05-19T07:00:00+02:00"
3232
String dateTimeISO; //"2018-05-19T07:00:00+02:00"
33-
sint16_t maxTempC; //20
34-
sint16_t maxTempF; //69
35-
sint16_t minTempC; //14
36-
sint16_t minTempF; // 56
37-
sint16_t avgTempC; // 17
38-
sint16_t avgTempF; // 62
39-
sint16_t tempC; // null
40-
sint16_t tempF; // null
41-
sint16_t pop; // 20
33+
int16_t maxTempC; //20
34+
int16_t maxTempF; //69
35+
int16_t minTempC; //14
36+
int16_t minTempF; // 56
37+
int16_t avgTempC; // 17
38+
int16_t avgTempF; // 62
39+
int16_t tempC; // null
40+
int16_t tempF; // null
41+
int16_t pop; // 20
4242
float precipMM; // 3.53
4343
float precipIN; // 0.14
4444
float iceaccum; // null
@@ -53,27 +53,27 @@ typedef struct AerisForecastData {
5353
uint8_t sky; // 99
5454
uint16_t snowCM; // 0
5555
uint16_t snowIN; // 0
56-
sint16_t feelslikeC; // 14
57-
sint16_t feelslikeF; // 56
58-
sint16_t minFeelslikeC; // 14
59-
sint16_t minFeelslikeF; // 56
60-
sint16_t maxFeelslikeC; // 20
61-
sint16_t maxFeelslikeF; // 69
62-
sint16_t avgFeelslikeC; // 17
63-
sint16_t avgFeelslikeF; // 63
64-
sint16_t dewpointC; // 11
65-
sint16_t dewpointF; // 51
66-
sint16_t maxDewpointC; // 13
67-
sint16_t maxDewpointF; // 55
68-
sint16_t minDewpointC; // 10
69-
sint16_t minDewpointF; // 51
70-
sint16_t avgDewpointC; // 11
71-
sint16_t avgDewpointF; // 52
56+
int16_t feelslikeC; // 14
57+
int16_t feelslikeF; // 56
58+
int16_t minFeelslikeC; // 14
59+
int16_t minFeelslikeF; // 56
60+
int16_t maxFeelslikeC; // 20
61+
int16_t maxFeelslikeF; // 69
62+
int16_t avgFeelslikeC; // 17
63+
int16_t avgFeelslikeF; // 63
64+
int16_t dewpointC; // 11
65+
int16_t dewpointF; // 51
66+
int16_t maxDewpointC; // 13
67+
int16_t maxDewpointF; // 55
68+
int16_t minDewpointC; // 10
69+
int16_t minDewpointF; // 51
70+
int16_t avgDewpointC; // 11
71+
int16_t avgDewpointF; // 52
7272
uint16_t windDirDEG; // 2
7373
String windDir; // "N"
7474
uint16_t windDirMaxDEG; // 40
7575
String windDirMax; // "NE"
76-
sint16_t windDirMinDEG; // 39
76+
int16_t windDirMinDEG; // 39
7777
String windDirMin; // "NE"
7878
uint16_t windGustKTS; // 6
7979
uint16_t windGustKPH; // 11

src/AerisObservations.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ void AerisObservations::doUpdate(AerisObservationsData *observations, String pat
4343
Serial.printf("[HTTP] Requesting resource at http://%s:%u%s\n", host.c_str(), port, path.c_str());
4444

4545
WiFiClient client;
46-
if(client.connect(host, port)) {
46+
#if defined(ESP8266)
47+
if (client.connect(host, port)) {
48+
#else
49+
if (client.connect(host.c_str(), port)) {
50+
#endif
4751
bool isBody = false;
4852
char c;
4953
Serial.println("[HTTP] connected, now GETting data");

src/AerisObservations.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
typedef struct AerisObservationsData {
3131
uint64_t timestamp;
3232
String dateTimeISO;
33-
sint16_t tempC;
34-
sint16_t tempF;
35-
sint16_t dewpointC;
36-
sint16_t dewpointF;
33+
int16_t tempC;
34+
int16_t tempF;
35+
int16_t dewpointC;
36+
int16_t dewpointF;
3737
uint8_t humidity;
3838
uint16_t pressureMB;
3939
float pressureIN;
@@ -60,12 +60,12 @@ typedef struct AerisObservationsData {
6060
String cloudsCoded;
6161
String icon;
6262
String iconMeteoCon;
63-
sint16_t heatindexC;
64-
sint16_t heatindexF;
65-
sint16_t windchillC;
66-
sint16_t windchillF;
67-
sint16_t feelslikeC;
68-
sint16_t feelslikeF;
63+
int16_t heatindexC;
64+
int16_t heatindexF;
65+
int16_t windchillC;
66+
int16_t windchillF;
67+
int16_t feelslikeC;
68+
int16_t feelslikeF;
6969
boolean isDay;
7070
uint64_t sunrise;
7171
String sunriseISO;

0 commit comments

Comments
 (0)