-->
Page 2 of 2

Re: DHT Json Web Server Example (Dashboard) -Very Simple

PostPosted: Sun Oct 09, 2016 1:33 pm
by Jph
exactly same issue - I am looking for a demo web page for the ESP8266 that actually is responsive. So far, haven't found one.
Event the simple 'led and buttons' type programs the refresh is excruciatingly slow.

Re: DHT Json Web Server Example (Dashboard) -Very Simple

PostPosted: Tue Oct 11, 2016 12:46 pm
by rudy
This is not JSON, but if you want to get fast response it works very well.

https://gist.github.com/bbx10/667e3d4f5f2c0831d00b

Re: DHT Json Web Server Example (Dashboard) -Very Simple

PostPosted: Thu Nov 23, 2017 8:59 am
by seaurchin
I know its an old thread I will highly appreciate if someone can please answer this !

I figured out that
Code: Select allclient.println("Content-Type: application/json");
in combination with
Code: Select alljson.prettyPrintTo(client);
does the actual job of output the json when we access the ip or ip/jsread.

However I want to change this behaviour to just the ip to return

Code: Select allclient.println("Content-Type: text/html");
and instead of ip/jsread I want it to be ip/json to return
Code: Select allclient.println("Content-Type: application/json");


how to do that ?

Re: DHT Json Web Server Example (Dashboard) -Very Simple

PostPosted: Sat Jan 27, 2018 5:11 pm
by GengusKahn
Hi there.....

Use this...(Faster....)Substitute your own variable data, sPath is the requested uri .........

Code: Select allelse if(sPath=="/json")   
   {
     ulJReqcount++;
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: application/json");
  client.println("Connection: close");
 // client.println("Connection: keep-alive");
  client.println("Access-Control-Allow-Origin: *");
  client.println("Access-Control-Allow-Methods: GET");
  client.println("Access-Control-Allow-Headers: Content-Type");
  client.println("Access-Control-Max-Age: 500");
  client.println();
     sResponse  = ("{\r\n\"temperature\": [\r\n");
     sResponse += pfTemp;
     sResponse += ("\r\n],\r\n\"humidity\": [\r\n");
     sResponse += pfHum;
     sResponse += ("\r\n],\r\n\"dewpoint\": [\r\n");
     sResponse += pfDew;
     sResponse += ("\r\n],\r\n\"Systemv\": [\r\n");
     sResponse += pfVcC/1000;
     sResponse += ("\r\n],\r\n\"Low_Hum_Today\": [\r\n");
     sResponse += pfHumLow;
     sResponse += ("\r\n],\r\n\"High_Hum_Today\": [\r\n");
     sResponse += pfHumHigh;
     sResponse += ("\r\n],\r\n\"Low_Temp_Today\": [\r\n");
     sResponse += pfTempLow;
     sResponse += ("\r\n],\r\n\"High_Temp_Today\": [\r\n");
     sResponse += pfTempHigh;
     sResponse += ("\r\n],\n\"Jsreqs\": [\r\n");
     sResponse += ulJReqcount;
     sResponse += ("\r\n],\r\n\"Uptime\": [\r\n\"");
     sResponse += duration1;
     sResponse += ("\"\r\n],\r\n\"TiMestamp\": [\r\n\"");
     sResponse += TMnow;
     sResponse += ("\"\r\n]\r\n}");
    // Send the JSON response to the client
    client.println(sResponse);     

   }