The planner has been deprecated, and should not be used for projects anymore (if you are building a commercial device, please note that you CANNOT use the planner in production).
Hi, just trying to get used to the new IDE, now that the planner is gone, does that means no more vimps? I presume have to write agent code in place of vimps; are the codes for previous existing vimps (like toggle, http in/out, cosm, etc) available?
Thks
Hey thanks for that beardedinventor, I have the admit that the planner is a good GUI approach and pretty clever concept, I guess that is more for beginners. A compilation or list of all useful/handy agent vimps will be really very useful resource.
What is not clear is should this be added to the agent code (I only see one “agent”). I would assume I could build a collection of agents for various devices. Same goes for the code, BTW. Can I have different code for each device? I have 2 temp sensors in one room. They are both referenced under one model. Both need different triggering temp thresholds so I end up editing the code; loading to device 1, then changing the code and loading to device 2.
I see the code: xivelyClient.agent.nut
Do I need to add this to my agent code, or is this already available to me? I’ve never added a full class into my IDE.
Then in my device code do I implement the new functionality by adding
`
client <- Xively.Client(“YOUR_API_KEY”);
// Create a channel and assign a value
tempChannel <- Xively.Channel(“Temperature”);
tempChannel.Set(current_temperature);
// Create a feed (replace FEED_ID with the Xively FeedID you are writting to
feed <- Xively.Feed(“FEED_ID”, [tempChannel]);
// Update Xively
client.Put(feed);
`
I already have agent code for twillio. I would expect another for Xively. Another for twitter, etc.
The client <- Xively.Client("") went just above that (I assume it doesn’t matter).
I put the “Push data to a feed” code into a device.on() method:
`device.on(“TempToXively”, function(v) {
// Create a channel and assign a value
tempChannel <- Xively.Channel(“Temp”);
tempChannel.Set(format("%3.1f",v));
// Create a feed
feed <- Xively.Feed(“myfeedno”, [tempChannel]);
// Update Xively
client.Put(feed);
});`
Then finally where I had this code in the device code: cosmWS[0].set(format("%3.1f",temp));
I changed it to: agent.send("TempToXively", temp);
Code checks out but nothing is going to Xively, yet. BTW, I’ve found that sometimes the code checks out OK but fails to run in the device. Oh well.
Next thing to understand:
How to pass the number of the device to the correct channel. I have 2 temp devices. How do I send one temp value to Temp, and the other temp value to Temp2?
@chrisjx - by convention, all files in our github are named ___.device.nut or ___.agent.nut - which indicated whether it is device or agent code. We should really have a better example of using Xively in github though.
Since Squirrel is an interpreted language, it’s not uncommon for your code to checkout and for it to fail at runtime.
A few things - Squirrel requires class and function definitions to occur before they are called / instantiated (ie - your client <- Xively.Client("") needs to go after your class definition).
You’re going to want to create two channels:
`device.on(“TempToXively”, function(data) {
// Create a channel and assign a value
local tempChannel1 = Xively.Channel(“Temp1”);
tempChannel1.Set(format("%3.1f",data.temp1));
// Create another Channel and assign a value
local tempChannel=2 = Xively.Channel(“Temp2”);
tempChannel2.Set(format("%3.1f", data.temp2));
// Create a feed
feed <- Xively.Feed(“myfeedno”, [tempChannel1, tempChannel2]);
// Update Xively
client.Put(feed);
});`
That should get you started… I think.
I also highly encourage you to work through @Tom’s TempBug Instructable. It goes through the process of reading a thermistor, sending the value to the agent, then passing that value to Xively.