-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from techniccontroller/main
Update with changes from main
- Loading branch information
Showing
8 changed files
with
219 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
name: Compile ESP8266 Sketch | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
compile: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Arduino CLI | ||
run: | | ||
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh | ||
echo "$(pwd)/bin" >> $GITHUB_PATH | ||
- name: Configure Arduino CLI | ||
run: | | ||
cat <<EOF > .cli-config.yml | ||
board_manager: | ||
additional_urls: | ||
- http://arduino.esp8266.com/stable/package_esp8266com_index.json | ||
EOF | ||
arduino-cli config init | ||
arduino-cli core update-index | ||
arduino-cli core install esp8266:esp8266 --config-file .cli-config.yml | ||
- name: Install Required Libraries | ||
run: | | ||
arduino-cli lib install "Adafruit GFX Library" | ||
arduino-cli lib install "Adafruit NeoMatrix" | ||
arduino-cli lib install "Adafruit NeoPixel" | ||
arduino-cli lib install "WiFiManager" | ||
arduino-cli lib install "Adafruit BusIO" | ||
- name: Compile Sketch | ||
run: | | ||
mv secrets_example.h secrets.h | ||
arduino-cli compile -v --fqbn esp8266:esp8266:nodemcuv2 wordclock_esp8266.ino |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
secrets.h | ||
/.vscode | ||
/build | ||
log.txt | ||
log*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include <ESP8266HTTPClient.h> | ||
#include "ntp_client_plus.h" | ||
#include "udplogger.h" | ||
|
||
int api_offset = 0; | ||
String api_timezone = ""; | ||
float api_lat = 0.0; | ||
float api_lon = 0.0; | ||
|
||
/** | ||
* @brief Request the timezone and other data from the IP-API | ||
* | ||
* @param logger UDPLogger object to log messages | ||
* @return bool true if the api request was successful | ||
*/ | ||
bool requestAPIData(UDPLogger &logger) { | ||
WiFiClient client; | ||
HTTPClient http; | ||
bool res = false; | ||
logger.logString("[HTTP] Requesting timezone from IP-API"); | ||
// see API documentation on https://ip-api.com/docs/api:json to see which fields are available | ||
if (http.begin(client, "http://ip-api.com/json/?fields=status,message,country,countryCode,region,regionName,city,zip,lat,lon,timezone,offset,query")) { | ||
int httpCode = http.GET(); | ||
|
||
if (httpCode > 0) { | ||
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) { | ||
String payload = http.getString(); | ||
|
||
api_timezone = getJsonParameterValue(payload, "timezone", true); | ||
logger.logString("[HTTP] Received timezone: " + api_timezone); | ||
|
||
String offsetString = getJsonParameterValue(payload, "offset", false); | ||
api_offset = offsetString.toInt() / 60; | ||
logger.logString("[HTTP] Received offset (min): " + String(api_offset)); | ||
|
||
String latString = getJsonParameterValue(payload, "lat", false); | ||
api_lat = latString.toFloat(); | ||
logger.logString("[HTTP] Received latitude: " + String(api_lat)); | ||
|
||
String lonString = getJsonParameterValue(payload, "lon", false); | ||
api_lon = lonString.toFloat(); | ||
logger.logString("[HTTP] Received longitude: " + String(api_lon)); | ||
|
||
} | ||
} | ||
else { | ||
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); | ||
res = false; | ||
} | ||
http.end(); // Close connection | ||
} | ||
else { | ||
logger.logString("[HTTP] Unable to connect"); | ||
res = false; | ||
} | ||
return res; | ||
} | ||
|
||
/** | ||
* @brief Get the Json Parameter Value object | ||
* | ||
* @param json | ||
* @param parameter | ||
* @return String | ||
*/ | ||
String getJsonParameterValue(String json, String parameter, bool isString) { | ||
String value = ""; | ||
if(isString) { | ||
int index = json.indexOf("\"" + parameter + "\":\""); | ||
if (index != -1) { | ||
int start = index + parameter.length() + 4; | ||
int end = json.indexOf("\"", start); | ||
value = json.substring(start, end); | ||
} | ||
} | ||
else { | ||
int index = json.indexOf("\"" + parameter + "\":"); | ||
if (index != -1) { | ||
int start = index + parameter.length() + 3; | ||
int end = json.indexOf(",", start); | ||
value = json.substring(start, end); | ||
} | ||
} | ||
return value; | ||
} | ||
|
||
/** | ||
* @brief Update the UTC offset from the timezone string obtained from the IP-API | ||
* | ||
* @param logger UDPLogger object to log messages | ||
* @param ntp NTPClientPlus object to set the UTC offset | ||
* @return int | ||
*/ | ||
void updateUTCOffsetFromTimezoneAPI(UDPLogger &logger, NTPClientPlus &ntp) { | ||
bool res = requestAPIData(logger); | ||
if (res) { | ||
ntp.setUTCOffset(api_offset); | ||
} | ||
} |
Oops, something went wrong.