How to make button one become an 'on/off' button on IOT buddy

Lol I would if was able to prgramme in the imp IDE, however as I don’t have my imp yet and it has not yet been blinked up I’m forced to write all programmes on notes for now, such is life :frowning:

Oh ok thanks for that Joel, I’ll change it back now and once I receive the prototype I’ll try both the device code you wrote and the agent code, thanks again Joel really appreciate it. I’ll hopefully update you soon.

@Joel I noticed that when I ran the code you suggested, the log stated that the imp.configure command is deprecated, is that a cause for concern?

Just remove that line… it is no longer needed now that the planner is deprecated.

OK the prototype doesn’t seem to be working for some reason, pretty sure its a hardware issue, however I just wanted to make sure the code was correct. Here is the code I used:

Agent Code

const API_KEY = "1234"; http.onrequest(function (req, resp) { try { local data = http.jsondecode(req.body); server.log("Received: " + req.body); if ("api-key" in req.headers && req.headers["api-key"] == API_KEY) { server.log(req.headers["api-key"]); if ("button1" in data) { device.send("button1", data.button1); device.on("button1", function(d) { local json = "{ \"status\" : { \"button1\" : \"" + d + "\" }}"; resp.send(200,json); }); } else if ("button2" in data) { device.send("button2", data.button2); device.on("button2", function(d) { local json = "{ \"status\" : { \"button2\" : \"" + d + "\" }}"; resp.send(200,json); }); } else if ("button3" in data) { device.send("button3", data.button3); device.on("button3", function(d) { local json = "{ \"status\" : { \"button3\" : \"" + d + "\" }}"; resp.send(200,json); }); } } else { local json = "{ \"status\" : { \"auth\" : \"no\" }}"; resp.send(401, json); } } catch (ex) { resp.send(500, "Internal Server Error: " + ex); } });

Device code: Unchanged from the code Joel very kindly provided

`agent.on(“button1”, function(a) {
local data = “”;
if (a == “”) {
hardware.pin1.write(1);
data = “Button 1 pressed.”;
}
agent.send(“button1”, data)
});
agent.on(“button2”, function(a) {
local data = “”;
if (a == “”) {
hardware.pin1.write(0);
hardware.pin2.write(0);
data = “Button 2 pressed.”;
}
agent.send(“button2”, data)
});
agent.on(“button3”, function(a) {
local data = “”;
if (a == “”) {
hardware.pin2.write(1);
data = “Button 3 pressed.”;
}
agent.send(“button3”, data)
});

//hardware.pin1.configure(DIGITAL_OUT);
//hardware.pin2.configure(DIGITAL_OUT);`

In the Pitchfork app I inputted the correct URL and I entered the correct API key. The log in the in the IDE confrims everything when I press a button in the app.

Is it definitely a hardware issue?

It looks correct, but if you have your pin configuration statements commented out they won’t do anything.
Server.log() is your debugging friend. Stick them in all over the place to make sure things are happening the way you want them to.
Do you have a multimeter to see if pins 1 & 2 are going high when you send the commands? You can have the Imp check as well with something like:

server.log("Pin 1 state: " + hardware.pin1.read());

I found a very small and inexpensive motor controller at Pololu.com that I used with an Attacknid. You can drive two motors in either direction at variable speeds.

Don’t have a multimeter but picking one up tomorrow. Do you think I should get rid of the pin configure bit? I tried that, same problem.

Can I ask what the name is for the motor controller?

You have to configure your pins or they won’t do anything. Having them commented out is the same as not configuring them at all. If you just want the pins configured as DIGITAL_OUT, then just remove the // before the statements in your code.

This is the one I used… it works great for small motors, but Pololu has a number of motor drivers. http://www.pololu.com/product/2135

Yup the // was the problem and now it Works perfectly! Thank you so much Joel, really appreciate it