Hello,
I’m a complete novice and have followed @jwehr excellent Adafruit tutorial, based on the work of @beardedinventor & @mjkuwp94 excellent work that allows temp readings to be sent along to both Xively and Twitter.
I’ve got the imp reporting the temperature of 2 x i2c thermometers and they return their temps in 2 x variables:
celcius_12
and celcius_89
at the end of the DEVICE code, I can send 1 of these variables to the Xively AGENT code by:
agent.send("Xively", celcius_12);
The Xively AGENT code sends this as Channel 1 but I’d like to see if anyone has adapted that AGENT code to send 2 Channels and if so would they be willing to share it with me. I imagine there’s some special way of sending both variables to the AGENT code as well.
Thanks @DolfTraanberg,
I’m going to have to apologise upfront, I’m really dumb with this stuff.
If I understand you correctly, your suggested DEVICE code amendments look to me to be sensible in so much as I have 2 x agents (called celcius_12 and another called celcius_89) is that correct?
I don’t seem to be able to attach the AGENT code that I’ve borrowed from @jwehr Adafruit tutorial which I understand was largely written by @beardedinventor & @mjkuwp94 as the “ATTACH A FILE” routine won’t let me attach either a RTF of ODT text file (I can’t find any other simple format available on my iMac Text Editor).
Make a table in the device code and send it to the agent: local probetemps = {"probe1temp" : probe1temp , "probe1reftemp" : probe1reftemp, "probe2temp" : probe2temp, "probe2reftemp" : probe2reftemp}; agent.send("Xively", probetemps)
And then to Xively from the agent: probe1 <- 0; probe2 <- 0; device.on("Xively", function(v) { channel1 <- Xively.Channel("Grill_Temperature"); channel1.Set(v.probe1temp); probe1 = v.probe1temp; channel2 <- Xively.Channel("Food_Probe_Temperature"); channel2.Set(v.probe2temp); probe2 = v.probe2temp; channel3 <- Xively.Channel("Grill_Temp_Reference"); channel3.Set(v.probe1reftemp); channel4 <- Xively.Channel("Food_Probe_Temp_Reference") channel4.Set(v.probe2reftemp); feed <- Xively.Feed("555555555555", [channel1, channel2, channel3, channel4]); client.Put(feed); });
Does that make sense? You make a table at the device and put your values in it, and then pass the table up to the agent. At the agent, when you want to get the values, you pull them back out of the table and pass them to Xively.
I have not helped with the tutorials so I am bit humbled and embarrassed that I have been getting mentioned.
I have on my long-term todo list to do something similar (multiple data series to Xively or TempDB ) so I will be able to help in the long run but in the short run I don’t have the time , sorry.
In general:
there is one Agent with each one Device.
I suggest JSON language to transfer the data. Here is a link to Xively which appears to show the format required.
Yep, you got it. You could make thermo1 and thermo2 local variables if you aren’t using them in any other functions… but that is a minor point. I use them in some other functions, which is why they are globals in my code… but both will work.
I’ve hit the “Build and Run” command button & it’s worked as expected!!!
That is AWESOME; I’m so excited.
I do have one other question regarding this kind of thing if you don’t mind?
As I’ve got 2 x impees doing the same thing but reporting to 2 different Xively “devices”, I’ve created 2 different Imp “Models”:
IR_Temp_Sense_for_Imp_1
and
IR_Temp_Sense_for_Imp_2
in each of these “models”, I’ve just updated the Xively AGENT code with the relevant “API_Key” and “Feed_ID” parameters.
The downside of this is that as I get more and more Imps using this same “Model” “prototype”, I have to keep producing more and more individual “Models” which becomes a nightmare to make “firmware” updates across the same prototype.
I assume there’s a way of doing the same thing from a single “model”?
That would be easier as I get more & more Impees but I don’t really see any way of achieving that with the Xively AGENT code the way it appears to need to work (although I rely on my NOVICE status when making such statements).
In my naive mind, I would think the only way I could achieve using a SINGLE IMP “MODEL” would be to use the same API_Key for all Xively “Devices” and then use the Impee’s unique ID # as the “Feed_ID” but that doesn’t appear to be at all possible given that Xively auto-assign the “Feed_ID” and there doesn’t appear to be any way of changing that (again; I rely on my NOVICE status when making such statements).
Yeah, there is nothing you can do about how Xively assigns Feed and Key values. And yes, you will want to make a separate model for every device you build where the code isn’t exactly the same. In fact, I’ve found that naming models uniquely is very helpful for keeping things organized. I believe the reason that things are set up the way they are is that someone selling a commercial Imp product would want to quickly assign a single model to many devices at once, with identical code. Commercial Imp products are definitely the priority of Electric Imp, since they pay the bills. We devs get to ride along on the service for free, which is pretty awesome.
Thanks Joel,
I just read a little of the the Xively blurb about “Provisioning”, I’m tipping that could be a way to get this done but; as you say, it’s a “Commercial” type product, so it’ll cost to go down that road just to see where it takes me.
Yeah, I totally agree with your about the AWESOME free service that Electric Imp provide to people like me who just want to muck around for hobbyist type pursuits. For $150, I’ve got everything I need to tinker with the Electric Imp till my heart’s content (that is until my wife gets sick of me sitting in front of a computer & cuts me off; then I’m in trouble).
Thanks for your (and everyone else’s) help with my learning; I greatly appreciate the time you guys & gals take for me.
I’m fairly obsessed with Imping things, and my wife has been quite understanding. I’ve learned a ton over the past year while dev’ing with the Imp. It is such a powerful device.