Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Php web page + Nodemcu

Status
Not open for further replies.

ajit_nayak87

Member level 5
Member level 5
Joined
Oct 30, 2017
Messages
86
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
981
Dear all,


I need some guideline to complete my project. Here is sample code where i could able to connect or any wifi network based on SSID.

1) In attached image how can i change Time to Indian Standard date & time
2)My first page should look like https://www.youtube.com/watch?v=oVTVopy0Tng as shown in video . where i could able to view parameter like this. keeping auto connect page same.

3) please suggest me in PHP how can i create my first webpage . All data is going to monitor locally.




Code HTML - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
  Simple.ino, Example for the AutoConnect library.
  Copyright (c) 2018, Hieromon Ikasamo
  [url]https://github.com/Hieromon/AutoConnect[/url]
 
  This software is released under the MIT License.
  [url]https://opensource.org/licenses/MIT[/url]
*/
 
#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>
 
#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
 
#define TIMEZONE    (3600 * 0530)    // Tokyo
#define NTPServer1  "ntp.nict.jp" // NICT japan.
 
//#define NTPServer1  "in.pool.ntp.org"
#define NTPServer2  "time1.google.com"
 
void rootPage() {
  String  content = 
    "<html>"
    "<head>"
    "<meta name="viewport" content="width=device-width, initial-scale=1">"
    "</head>"
    "<body>"
    "<h2 align="center" style="color:blue;margin:20px;">Hello, world</h2>"
    "<h3 align="center" style="color:gray;margin:10px;">{{DateTime}}</h3>"
    "<p style="padding-top:10px;text-align:center">" AUTOCONNECT_LINK(COG_32) "</p>"
    "</body>"
    "</html>";
  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 setup() {
  //delay(1000);
  Serial.begin(115200);
  Serial.println();
 
  // Behavior a root path of ESP8266WebServer.
  Server.on("/", rootPage);
 
  // Enable saved past credential by autoReconnect option,
  // even once it is disconnected.
  Config.autoReconnect = true;
  Portal.config(Config);
 
  // Establish a connection with an autoReconnect option.
  if (Portal.begin()) {
    Serial.println("WiFi connected: " + WiFi.localIP().toString());
    configTime(TIMEZONE, 0, NTPServer1, NTPServer2);
  }
}
 
void loop() {
  Portal.handleClient();
}







autoconnect.jpgWebpage1 (1).jpgConfig1.jpg
 
Last edited by a moderator:

There are some differences between PHP versions but this should work.
Remove these two lines:
#define TIMEZONE (3600 * 0530) // Tokyo
#define NTPServer1 "ntp.nict.jp" // NICT japan.
replace them with this:
date_default_timezone_set('Asia/Kolkata');
The web page should work if the browser supports HTML5 but to make it more compatible you need to add a DOCTYPE statement, something like this:
HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n");
before the first 'html' in 'content'.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top