My first Impee : a cheap Wifi temperature sensor

I received my Imp a few weeks ago along with a Sparkfun breakout board.

Configuring it to connect to your wifi network is very simple but you need to use either an iPhone or an Android phone.The Imp app just asks for you wifi detail, then makes the phone screen blink sending the configuration thru a sensor on the edge of the Imp. Simple and clever. You’ll find all information on Imp website here.

The hardware part

I also got

  • a very cheap LM35DZ temperature sensor
  • a 3.7V / 850mAh Li-Ion battery
  • an Adafruit Li-Ion battery charger

and hooked all this up together.

Impee

I connected LM35DZ data pin on pin 9.

To power the imp, you have 2 main choices :

  • USB
  • Battery
  • other external power

In order to choose battery or USB power, you need to solder a break away header and use a jumper. Please note this is not provided with the breakout board.

Imp Breakout Power

The software part

Ok, now we got to program this thing to measure temperature and sending it to some emoncms site for instance.

Actually, there are 2 things you need to program. the Imp itself : the “device”. But there is not much you can do with it. Typically, you can’t send an http request. You need to send the data to an Electric Imp web service : the “agent”. The agent can do many more things… like sending an http requests to emoncms.

So first, the device program

Then the agent program

Easy, isn’t it ?.

The results

Worked on battery (850mAh 3.7V) for 15 days. Here are temperature and voltage graph from emoncms :

Impee-Emoncms

Conclusion

I liked the easy of use of the gizmo : solder a temp sensor, type 10 lines of program, and here we go ! Also, I like the fact that you can send data to the “agent” to do potential heavy processing on server side thus saving power on the device (you can also send message from the agent to the device.)

I do not like depending on a Cloud based service that might not be always available. Not that I do not wish Electric Imp to be sucessfull and have a long life… but… you know… I just would like to have the option to host the agent myself.

2 thoughts on “My first Impee : a cheap Wifi temperature sensor

  1. Hi there….
    what does it mean…this line:
    local request = http.get(“http://myemoncmssite.com/input/post.json?node=101&apikey=mayapijey&json=”+jsonString);

    a propos….I would like to ask you. There is the code for reading temperature and send the data to agent. How should I continue to:
    – send the data to the database (phpMyAdmin)
    – if temperature exceed 30 Celsius -> send alert to my mobile phone


    __________________________device_______________________

    therm <- hardware.pin5; // assign hardware.pin5 to a global variable
    therm.configure(ANALOG_IN); // configure pin5 to be an ANALOG_IN

    const b_therm = 3977.0; // these constants are particular to the thermistor
    const t0_therm = 298.15;

    const R2 = 10000.0; // the resistor in the circuit (10KΩ)

    function GetTemp_C() {
    local Vin = hardware.voltage();
    local Vout = Vin * therm.read() / 65535.0;
    local R_Therm = (R2 * Vin / Vout) - R2;
    local ln_therm = math.log(R2 / R_Therm);
    local temp_C = (t0_therm * b_therm) / (b_therm - t0_therm * ln_therm) - 273.15;
    return temp_C;
    }

    function poll() {
    // Get and log Celsius temperature
    local temp = GetTemp_C();
    server.log(temp + " C");
    agent.send("ch1",temp);
    imp.wakeup(5.0, poll); // wakeup in 5 seconds and read the value again:
    }
    poll()
    _________________________________________________________

    ___________________________agent__________________________

    function temp(tempIn){

    server.log("afent received"+tempIn);
    }
    device.on("ch1",temp);

    __________________________________________________________

    Thank you

    • Hello Pablo,

      what does it mean…this line:
      local request = http.get(“http://myemoncmssite.com/input/post.json?node=101&apikey=mayapijey&json=”+jsonString);

      I am using emoncms software to store data I collect with my IoT gizmos. Emoncms is an “Open-source energy visualisation” tool but also much more. You can either build your own emoncms site or use the public one. More information here : http://emoncms.org/

      How should I continue to:
      – send the data to the database (phpMyAdmin)

      I don’t think you can send data to a MySQL database using phpMyAdmin. You should use a software like emoncms 😉

      – if temperature exceed 30 Celsius -> send alert to my mobile phone

      I you use emoncms (again ;-)) you could use its event module which allows sending notifications using email, tweeter, prowl, name or mqtt.

      You could also use directly agent code using a service like prowl : http://www.prowlapp.com. Have a look here : http://forums.electricimp.com/discussion/1090/agent-ios-push/p1. You’ll find a sample code :

      function Push(_apiKey, _application, _event) {
      local url = "https://api.prowlapp.com/publicapi/add?"
      local query = { apikey = _apiKey, application = _application, event = _event };
      url += http.urlencode(query);

      server.log("Posting: " + url);
      local result = http.post(url, {}, "").sendsync();
      server.log(result.statuscode + ": " + result.body);
      }

      Hope this helps.
      JS

Leave a Reply

Your email address will not be published.