Completely lost - all help appreciated!

My Imp has been running for nearly a year - but had a couple of ‘outs’ for a few days over the last month or three.
So I visited the dev centre for the first time today …Not having seen the dramatic changes to the interface (and function ?) - for a while.

I have an IMP which was sending temp data to Xively. Having visited the dev centre, its now not working.
The IMP code stills runs happily, but the agent code doesnt seem to post to Xively.
I cant find a simple explanation of the ‘handshake’ between the two - The old interface made it clear by visually linking the agent to the imp…and I clearly dont understand whats going on now.

My code is now a combination of agent (from the Xively tutorial); and Imp code (from a very old tutorial). The two dont seem to work together.
Can someone explain how I get the IMP to fire the agent successfully please.
(BTW, when I click on the agent URL at the top of the dev window, I get ‘No HTTP Handler’. - if that helps!

const FEED_ID = “7311261”;
const API_KEY = “5F5X01182736646123HHHHH6D”;
function send_xively(body) { //take in csv value
local xively_url = “” + FEED_ID + “.csv”; //setup url for csv
server.log(body); //pring body for testing
local req = http.put(xively_url, {“X-ApiKey”:API_KEY, “Content-Type”:“text/csv”, “User-Agent”:“Xively-Imp-Lib/1.0”}, body); //add headers
local res = req.sendsync(); //send request
if(res.statuscode != 200) {
server.log("error sending message: “+res.body);
}else device.send(“status”, (res.statuscode + " OK”)); //sends status to uart. this can be removed if not desired

server.log(“device on”);

//send preformatted multi-ds csv
send_xively(feedCSV);         //send to function to call xively


//IMP Code
// April with a 10k, 1% from 3V3 to pin9 and 10k B57861S0103F040 NTC Thermistor from pin9 to pin8
// pin8 TEMP_READ_EN_L - drive low to enable temp reading (great for batteries!)
// pin9 ANALOG NTC value

// turn on WiFi power save to reduce power consumption when awake

// Output structure for sending temperature to server
local tempOut = OutputPort(“Temperature ©”, “number”);

// Configure Pins
// pin 8 is driven high to turn off temp monitor (saves power) or low to read
// pin 9 is the middle of the voltage divider formed by the NTC - read the analog voltage to determine temperature

// all calculations are done in Kelvin
// these are constants for this particular thermistor; if using a different one,
// check your datasheet
const b_therm = 3560;
const t0_therm = 294.15; //Code modified to offset (-4) to calibrate actual sensor

function getTemp() {
// turn on the thermistor network
// gather several ADC readings and average them (just takes out some noise)
local val = 0;
for (local i = 0; i < 10; i++) {
val +=;
val = val/10;
// turn the thermistor network back off

// to read the battery voltage reliably, we take 10 readings and average them
local v_high  = 0;
for(local i = 0; i < 10; i++){
    v_high += hardware.voltage();
v_high = v_high / 10.0;
// scale the ADC reading to a voltage by dividing by the full-scale value and multiplying by the supply voltage
local v_therm = v_high * val / 65535.0;
// calculate the resistance of the thermistor at the current temperature
local r_therm = 10000.0 / ( (v_high / v_therm) - 1);
local ln_therm = math.log(10000.0 / r_therm);
local t_therm = (t0_therm * b_therm) / (b_therm - t0_therm * ln_therm) - 273.15;
// convert to fahrenheit for the less-scientific among us
local c =  t_therm //(t_therm) * 9.0 / 5.0 + 32.0;
// format into a string for the string output port
local c_str = format("%.01f", c)
server.log("Current temp is " + c_str + " C");
// emit values to our output port
imp.wakeup(30, getTemp);

agent.on(“status”, function(code) {
server.log(“agent is on”);
// Configure on planner and register with imp server
imp.configure(“Jons Thermometer”, [], [tempOut]);

You can try this in the device

function _insteadOfOutputPort(temperature){



function testrun(){



and this in the agent


server.log(currenttemp + " was sent from the device");

//send to Xively here


It will only run once, just when you load new code. It is intention as this is only an example.

You can call function _insteadOfOutputPort in the device instead of using the output port.

In the agent put code for sending to xively where noted in the comments.

I use a similar version of your code. Except mine is modified to post data from 5 thermistors to xively.

My unit also stopped working last night, around midnight. It was running for days straight before it stopped. The imp is on and sending data, but it’s not getting to xively.

This happened two or three weeks ago and at least one thread on the forum talks about it. I was never sure what the real problem was…mention was made to the imp planner changes, or that we overloaded xively with data from the same ip address (and was then unblocked and worked again), or that Xively itself was changed/broken?

Based on what I saw a few weeks ago, I’m going to wait a day or two before I start trying to fix things.

Thanks solarishot - yeah I have had a few outages, and (Im guessing) its lack of support for the deprecated technology… so I took the plunge.
The problem Im having is understanding the handshake between imp and agent… the (rather slow) videos explaining the new interface dont help - as it the conceptual how they interact thats baffling me.
FUndamentally the imp isn’t making the agent code fire (and the ‘no http handler’ error isn’t helping).

thanks for the thought mjkuwp94 - but the “agent.send” command seems to do nothing. the agent code seem to ignore it (as far as I can tell).

Do you have agent.send(“message name”) and device.on(“message name”) named identically within your device and agent code respectively so the agent and device can communicate appropriately?

I don’t see a device.on(“message name”) within your agent code (unless I’m just missing it), so this would be why the agent wouldn’t respond.

I wrote the code into one of my devices before posting it. All it will/should do is cause a planner log message to occur 5 seconds after the Device boots up. you would need to fill in your own function to get the stuff to Xively

also, the reason you get ‘no http handler’ is possibly because you do not have this function.


and you may not need it if your data is only going one way.

There are also periodic problems with xively from what I see here on this forum; I don’t use it anymore so I wouldn’t know directly about that.

My xively site started posting data from my 5 thermistors again today at around 12:30pm. That means the latest xively outage was for about 12.5 hours (for me, anyway). Not sure if others experienced the same? Just wanted to let you know, jonandel. Maybe it helps.

Edit @2:41pm Eastern Standard. Xively seems to have been on/off since my last comment about it working again. For the first time I see something funny…for the last 2 hours my 5 channels were updating at different times. Have not seen that before…interesting.

I having a similar issue with Xively currently. It is no longer receiving my 15 minute Temperature updates (still using the Blueprint method for this) Last time this happened Xively had blacklisted the electricimp IP.

Thanks for the confirmation, ChrisRusty. Not sure if this issue is due to Xively or not, but i think it convinced me to finally try the new code and abandon the planner, just to be safe. I’m laughing at myself though…I just spent a hour+ trying to get the new code working before realizing that if Xively is wonky, I’m probably not going to see my efforts work. Anyway, to be safe, I’m waiting until I see things at Xively working again before I go and try the new code for Xively that I have seen…

Re: Xively - I’m currently posting (however with a non-Imp device in this particular case) every 15 minutes, and haven’t noted any outages or unusual behavior over the last week. Just an fyi.

I’ve push two temperatures to Xively every 30 seconds continuously, and haven’t seen an outage. I don’t use the planner. The Xively code isn’t hard to adapt. The Electric Imp tutorial that I wrote for the Adafruit Learn site has an example, and pushes temperature from a thermocouple. Take a look at that if it helps.

No known outages: if anyone is seeing problems with agents posting to Xively we’d like to know about it.

Blueprint looks like it had a wobble about 5 hours ago (17:28 UTC) but auto-restarted itself in under 60 seconds. It’s possible that Xively could have forgotten about the whitelist, I guess. I just checked our UK office feed and there was a gap ~1 day long until about 10 mins ago but I don’t know if that one is using agents or the legacy blueprint stuff - it’s been running a long while.

no connection loss with xively for at least a week now

Appears as though I was affect by the UK office feed, Xively feed started working again a short while ago after being down for hours. I had also emailed Xively support and things started working shortly after I received a response from them.

Chris, are you using the “cosm” block in the blueprint or an agent?

Cosm block in the blueprint. Not got around to migrating this bit to my agent code but I intend to.

Our UK office confirmed they were still using blueprint. Seems like this isn’t so happy as people using agents appear to have had no outages.

The recommendation is to switch to agents :slight_smile: