/* * 2016-11-26 dvb * An example server with two pages and buttons to go between them. */ #include // These includes arent used in this file, but tells Arduino IDE that this project uses them. #include #include OmWebServer s; OmWebPages p; void registerDevice() { String url = "/misc/2016/X/devices.php?deviceName=Experiment1&deviceIp="; url += omIpToString(s.getIp()); String host = "dvb.omino.com"; // url = "/"; // host = "google.com"; WiFiClient client; const int httpPort = 80; if (!client.connect(host.c_str(), httpPort)) { Serial.println("connection failed"); return; } static char s[1024]; sprintf(s, "GET %s HTTP/1.1\r\n" "Host: %s\r\n" "Connection: close\r\n\r\n", url.c_str(), host.c_str()); client.printf("%s", s); Serial.printf("%s", s); delay(1000); // Read all the lines of the reply from server and print them to Serial Serial.println("Respond:"); while(client.available()){ String line = client.readStringUntil('\r'); Serial.print(line); delay(20); } Serial.println("did"); } void statusCallback(const char *ssid, bool trying, bool failure, bool success) { if(success) registerDevice(); } void setup() { Serial.begin(115200); Serial.printf("\n\n\nWelcome to the Sketch\n\n"); // Add networks to attempt connection with. // It will go down the list and repeat until on succeeds. // This only happens when tick() is called. s.addWifi("connection will fail", "haha"); s.addWifi("omino warp", "0123456789"); s.addWifi("caffe pergolesi", "yummylatte"); // Configure the web pages // This is just setting them up; they'll be delivered // by the web server when queried. p.beginPage("page 1"); p.addPageLink("page 2"); // shows up as a button. // This html code is executed on each request, so // current values and state can be shown. p.addHtml([] (OmXmlWriter &w, int ref1, void *ref2) { w.addContent("welcome to page 1"); w.addElement("hr"); w.addContent("the milliseconds are..."); w.beginElement("h1"); w.addContentF("%dms", millis()); w.endElement(); }); p.beginPage("page 2"); p.addPageLink("page 1"); p.addHtml([] (OmXmlWriter &w, int ref1, void *ref2) { w.addContent("welcome to page 2"); w.addElement("hr"); w.beginElement("pre"); w.addContentF("serverIp: %s\n", omIpToString(s.getIp())); w.addContentF(" yourIp: %s\n", omIpToString(s.getClientIp())); w.endElement(); }); s.setHandler(p); s.setStatusCallback(statusCallback); } int ticks = 0; void loop() { delay(10); s.tick(); }