Comments (4)
What do you have a doubt about?
Can you confirm the policy before posting the issue?
from autoconnect.
oh sorry I didn't notice that
`/*
Simple.ino, Example for the AutoConnect library.
Copyright (c) 2018, Hieromon Ikasamo
https://github.com/Hieromon/AutoConnect
This software is released under the MIT License.
https://opensource.org/licenses/MIT
*/
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WebServer.h>
#endif
#include <time.h>
#include <AutoConnect.h>
static const char AUX_TIMEZONE[] PROGMEM = R"(
{
"title": "TimeZone",
"uri": "/timezone",
"menu": true,
"element": [
{
"name": "caption",
"type": "ACText",
"value": "Sets the time zone to get the current local time.",
"style": "font-family:Arial;font-weight:bold;text-align:center;margin-bottom:10px;color:DarkSlateBlue"
},
{
"name": "timezone",
"type": "ACSelect",
"label": "Select TZ name",
"option": []
},
{
"name": "newline",
"type": "ACElement",
"value": "
"
},
{
"name": "start",
"type": "ACSubmit",
"value": "OK",
"uri": "/start"
}
]
}
)";
typedef struct {
const char* zone;
const char* ntpServer;
int8_t tzoff;
} Timezone_t;
static const Timezone_t TZ[] = {
{ "Europe/London", "europe.pool.ntp.org", 0 },
{ "Europe/Berlin", "europe.pool.ntp.org", 1 },
{ "Europe/Helsinki", "europe.pool.ntp.org", 2 },
{ "Europe/Moscow", "europe.pool.ntp.org", 3 },
{ "Asia/Dubai", "asia.pool.ntp.org", 4 },
{ "Asia/Karachi", "asia.pool.ntp.org", 5 },
{ "Asia/Dhaka", "asia.pool.ntp.org", 6 },
{ "Asia/Jakarta", "asia.pool.ntp.org", 7 },
{ "Asia/Manila", "asia.pool.ntp.org", 8 },
{ "Asia/Tokyo", "asia.pool.ntp.org", 9 },
{ "Australia/Brisbane", "oceania.pool.ntp.org", 10 },
{ "Pacific/Noumea", "oceania.pool.ntp.org", 11 },
{ "Pacific/Auckland", "oceania.pool.ntp.org", 12 },
{ "Atlantic/Azores", "europe.pool.ntp.org", -1 },
{ "America/Noronha", "south-america.pool.ntp.org", -2 },
{ "America/Araguaina", "south-america.pool.ntp.org", -3 },
{ "America/Blanc-Sablon", "north-america.pool.ntp.org", -4},
{ "America/New_York", "north-america.pool.ntp.org", -5 },
{ "America/Chicago", "north-america.pool.ntp.org", -6 },
{ "America/Denver", "north-america.pool.ntp.org", -7 },
{ "America/Los_Angeles", "north-america.pool.ntp.org", -8 },
{ "America/Anchorage", "north-america.pool.ntp.org", -9 },
{ "Pacific/Honolulu", "north-america.pool.ntp.org", -10 },
{ "Pacific/Samoa", "oceania.pool.ntp.org", -11 }
};
#if defined(ARDUINO_ARCH_ESP8266)
ESP8266WebServer Server;
#elif defined(ARDUINO_ARCH_ESP32)
WebServer Server;
#endif
AutoConnect Portal(Server);
AutoConnectConfig Config; // Enable autoReconnect supported on v0.9.4
AutoConnectAux Timezone;
void rootPage() {
String content =
""
""
"<meta name="viewport" content="width=device-width, initial-scale=1">"
""
""
"<h2 align="center" style="color:blue;margin:20px;">Hello, world"
"<h3 align="center" style="color:gray;margin:10px;">{{DateTime}}"
"<p style="text-align:center;">Reload the page to update the time.
"<p style="padding-top:15px;text-align:center">" AUTOCONNECT_LINK(COG_24) ""
""
"";
static const char *wd[7] = { "Sun","Mon","Tue","Wed","Thr","Fri","Sat" };
struct tm *tm;
time_t t;
char dateTime[26];
t = time(NULL);
tm = localtime(&t);
sprintf(dateTime, "%04d/%02d/%02d(%s) %02d:%02d:%02d.",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
wd[tm->tm_wday],
tm->tm_hour, tm->tm_min, tm->tm_sec);
content.replace("{{DateTime}}", String(dateTime));
Server.send(200, "text/html", content);
}
void startPage() {
// Retrieve the value of AutoConnectElement with arg function of WebServer class.
// Values are accessible with the element name.
String tz = Server.arg("timezone");
for (uint8_t n = 0; n < sizeof(TZ) / sizeof(Timezone_t); n++) {
String tzName = String(TZ[n].zone);
if (tz.equalsIgnoreCase(tzName)) {
configTime(TZ[n].tzoff * 3600, 0, TZ[n].ntpServer);
Serial.println("Time zone: " + tz);
Serial.println("ntp server: " + String(TZ[n].ntpServer));
break;
}
}
// The /start page just constitutes timezone,
// it redirects to the root page without the content response.
Server.sendHeader("Location", String("http://") + Server.client().localIP().toString() + String("/"));
Server.send(302, "text/plain", "");
Server.client().flush();
Server.client().stop();
}
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Config.apid = "Server for testing";
Config.psk = "Cepl2014";
// Enable saved past credential by autoReconnect option,
// even once it is disconnected.
// AC_SAVECREDENTIAL_AUTO;
Config.autoReconnect = true;
Portal.config(Config);
// Load aux. page
Timezone.load(AUX_TIMEZONE);
// Retrieve the select element that holds the time zone code and
// register the zone mnemonic in advance.
AutoConnectSelect& tz = Timezone.getElement("timezone");
for (uint8_t n = 0; n < sizeof(TZ) / sizeof(Timezone_t); n++) {
tz.add(String(TZ[n].zone));
}
Portal.join({ Timezone }); // Register aux. page
// Behavior a root path of ESP8266WebServer.
Server.on("/", rootPage);
Server.on("/start", startPage); // Set NTP server trigger handler
// Establish a connection with an autoReconnect option.
if (Portal.begin()) {
Serial.println("WiFi connected: " + WiFi.localIP().toString());
}
}
void loop() {
Portal.handleClient();
}`
above are my code . I'm using iPhone. My doubt was during I uploading the coding the hone page timer remain as 1970 year and the clock remain as 0h 0 second . Its that able to change it as a real time clock or UTC clock ?
from autoconnect.
Simple.ino as an example has two assumptions. One is that the ESP module was able to connect to the Internet, and the other is to display the time by reloading the web page manually. It's not a real-time clock sketch application.
from autoconnect.
This topic is not relevant to the improvement of the AutoConnect library but is maintained to clarify the Simple.ino
example's intent.
from autoconnect.
Related Issues (20)
- ESP32 problem HOT 8
- Mqtt Example HOT 2
- Using "AutoConnectCore.h" header and running into errors HOT 2
- AutoConnect to offer captive portal for 5min even if ESP32 is WiFi-Connected HOT 1
- AutoConnect on WiFi connection error shows too many redirects. HOT 2
- AutoConnectCore Not Working HOT 1
- Failing to store network HOT 2
- AutoConnect not longer runningh on ESP8266 HOT 2
- Use Autoconnect library with ESP now HOT 1
- Issue after updating libraries in my PIO project: enableCors() HOT 2
- Strange Issue
- WiFiClientSecure is not working with AutoConnect HOT 1
- how to use esp8266 with WiFiClientSecure
- AutoConnectPageImpl.hpp:1001:20: error: there are no arguments to 'spi_flash_get_chip_size' that depend on a template parameter, so a declaration of 'spi_flash_get_chip_size' must be available [-fpermissive] HOT 2
- Save data from Custom Page to flash HOT 2
- esp32: frozen loop() and kicked out of the WiFi connection at Configure new AP
- WPA2 Enterprise support
- Captive portal cause watchdog triggering
- Possibility to change pass for SoftAP from webui.
- Fresh Install and even the simplest of code will not compile HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autoconnect.