Code examples
You can find completed snippets of main.cpp
and Platformio.i
ni
at .
In that updated main.cpp
, you can see three new functions created by ChatGPT based on the previous version:
connectToWiFi()
: The function to connect Wi-Fi by SSID and passwordpingHost()
: Ping google.com to check whether the public internet is accessiblesyncNTP
: Obtain the current date and time from the public internet NTP server
In addition, in the updated platformio.ini, we also adopt a flexible approach to store and pass the following critical parameters to the main code using build_flags
. When prompting, you can ask ChatGPT to use the same name macros from platformio.ini. Doing so would ensure that the output of ChatGPT does not use different names:
build_flags = …….. -D WIFI_SSID=\"WiFi_TEST\" //replace it by your actual Wi-Fi SSID -D WIFI_PASSWORD=\"WiFi_Password\" ...