Communication with an Android app

I wasn’t sure if I should post this in Mobile or Planner, sorry if this is in the wrong sub.

A project I’m working on uses an Android app to modify/read states on an imp. The imp is communicating with sensors, and should be able to inform the app of changes to states. What I’d like to do is have the app read the imp state to update the GUI, but from what I can tell there’s no storing of data on the Planner or electricimp.com cloud. All I really need is a few bytes at most, do I need a web server?

http://devwiki.electricimp.com/doku.php?id=electricimpapi:server:setpermanentvalues

I may have not been clear, but I also need the Android app to view the values (or even modify them) as well. My impression is that’s not possible with permanentvalues.

have you seen the program Electric Imp Toggle by talexander in the play store? Maybe that will help.

The app sends a command to the imp. The imp reads/writes the table, and responds to the app. The app doesn’t talk directly to the table.

The imp reads/writes the table, and responds to the app

I would like to do this, but it’s been my understanding that an imp could not communicate directly with an app. Have I missed something?

Not directly, via the EI cloud.

A simple example based on the http.onrequest() documentation, using Agent.
This example assumes a switch (to GND) on pin 1, and a LED (to GND, through 470 ohm resistor) on pin 2:

Agent:
`
responses <- []

http.onrequest(function(req, res) {
responses.push(res)
local val = -1
if(“led” in req.query) {
val = req.query.led == “on” ? 1 : 0
}
device.send(“ping”, val)
})

device.on(“pong”, function(data) {
foreach(res in responses) {
res.send(200, format(“switch: %s”, data ? “on” : “off”))
}
responses = [];
})`

Device:
`
local sw = hardware.pin1
local led = hardware.pin2

agent.on(“ping”, function(data) {
if(data > 0) {
led.write(1)
server.log(“led on”)
}
else if(data == 0) {
led.write(0)
server.log(“led off”)
}
local state = !sw.read()
server.log(format(“switch %s”, state ? “on” : “off”))
agent.send(“pong”, state)
})

imp.configure(“led-switch-agent”, [], [])

sw.configure(DIGITAL_IN_PULLUP)
led.configure(DIGITAL_OUT)
`

Point a browser to https://agent.electricimp.com/your-agent-id/ to query the switch state, append parameter led=on or led=off to control the led:
https://agent.electricimp.com/your-agent-id/?led=on

Of course you could also perform the request from an Android or iPhone app, and build an appropriate GUI for it.

Oh, that looks great! I was under the impression agents weren’t available yet. I’ll give it a try, thanks!