Best source of info using agent to display temp data online

Hi, I’m curious what code is used to display a temperature value (from thermistor) on the agent website for my imp? I see in the examples how to make buttons, and control stuff remotely, but my priority is simply to post temperature data measured by the imp to the agent’s online page (ie https://agent.electricimp.com/xxxxxxxxxxxx).

Do you have any of the code completed? You basically need five parts:

  1. Read the thermistor data at the device.
  2. Send the data from the device to the agent.
  3. Read and store the data in a variable on the agent.
    Then you need:
  4. A function to handle incoming HTTP requests (http.onrequest()).
  5. Some HTML that includes your temperature data to respond to the browser.

I’ve hacked up @beardedinventor’s code, as well as some of the Snackbot code, and here is an example of HTML that I send back from one of my temperature monitor projects.

`const html1 = @"

    <link href=""//d2c5utp5fpfikz.cloudfront.net/2_3_1/css/bootstrap.min.css"" rel=""stylesheet"">
    <link href=""//d2c5utp5fpfikz.cloudfront.net/2_3_1/css/bootstrap-responsive.min.css"" rel=""stylesheet"">

    <title>impTherm&sup2</title>
</head>
<body>
    <div class='container'>
        <div class='well' style='max-width: 300px; margin: 0 auto 10px; text-align:center;'>
            <h1>impTherm&sup2<h1>
            <h3>Probe 1: ";

const html2 = @"&degF

Probe 2: “;
const html3 = @”&degF




"; `

Here is an HTTP request handler example from my code:

http.onrequest(function(request, response) { if (request.body == "") { local html = format(html1 + ("%s", probe1) + html2 + ("%s", probe2) + html3); response.send(200, html); } else { response.send(500, "Internal Server Error"); } });

That might not be the most elegant way to it, but it works.

yes, and then use AJAX and an interval in that web page and you can create something that keeps updating

controlCloud has an example set of code that shows the technique well although I don’t think this shows the self-hosting aspect.

controlCloud April example

This is a related discussion

sorry it is not all buttoned up into one clean example.

This page:
http://www.htmltemplates.net/preview/template_12/index.html
is a free html template I copied.

I hosted the images to a website I own:
<img src=\"http://www.mysite.com/images/spacer.gif

I also hosted the style sheet there and I am using this line in my onrequest routine.
htmlresp += "<link href=\"http://www.mysite.com/css/style.css\" rel=\"stylesheet\" type=\"text/css\">";
I can copy this link to a web browser page and the text of the style sheet is displayed ok.

I basically converted the html template above to Imp code in my Agent. I wanted that page to display then I will edit and modify the page. It seems the style.css file is not being loaded. I get all the images and the links but I don’t get any background or formatting when the page loads out of the Imp. Should I try hosting that style sheet somewhere else?

Try using Firebug or one of the developer console addons. Might help to determine why your CSS isn’t being loaded?

Here is something I found by using the “Inspect Element” screens in Chrome:
GET https://mysite.com/css/style.css net::ERR_SSL_PROTOCOL_ERROR