Sending messages to the web server from Imp

#1

Hello, We have developed an Android application that controls a smart lock via the electric imp. Our program has a state machine that displays what state the lock and door are in on the server log of the Imp. The way we this information will be transmitted in the Android application will be by using HTTP requests to read the web agent. Does anybody have any method for accomplishing this? Please let me know.

#2

I think we will need a bit more information. For example, Can anyone use the app and open the door, or is there some sort of user/password? That follows with a question about where all of that security information is stored. I mention this because if you do a request to the agent (such as a GET or POST), you could or should be validating who is sending it, in the form of an API key (as an example). Or maybe your Android app is part of a whole other website that has all of the administrative controls, where an admin person or users register and log-in to get door access permission, so they can then use their app.

Maybe I’m over-thinking it? Sometimes I get rambling. Is your project just a one or two imp thing, or is this a whole “blessed” commercial product?

#3

Our android application uses fingerprint authentication to access the main interface. So only the user of the phone can access the app thus the content in the Imp. We are only using one imp for this. This is a project for senior design.

#4

As always, Dev Center is your friend.

TL/DR: Set the agent to manage requests (from the app in this case) for imp state data, or to send commands to the imp.

#5

OK, so you know that your imp agent URL will be private and nobody will be able to see that. If anyone finds out what the agent URL is, then it could be a problem. Meanwhile, your Android app, once the fingerprints are verified, will do a POST to the imp agent. You should send along some sort of random “key” number to make it more secure, in case someone finds out the imp agent URL. The post (or command) you send the agent will be to 1) Unlock the door, 2) Request the status of the door (opened or closed or ajar), 3) Lock the door (or it will always lock automatically), 4) Request the status of the lock. Maybe “locked” and “unlocked” is different than “door opened” or “door closed”. Those are 4 different things?

Describe what commands you need to give, and what feedback you need from the imp sensors. JSON is a great way to communicate information back and forth. The Imp likes JSON. I’m not familiar with Android apps, and so I don’t know anything about the app native language. I do PHP.

So you POST to the agent an array of JSON values (the key plus any ‘commands’). No matter what you send, the agent will do its thing and return back a code indicating what the status is, and the key, so you know you are getting the data back from the agent and not someone else.

Is that sort of the “flow” you are attempting? Can your app assemble a JSON array and do a POST to a URL (in this case it’s the Imp Agent URL)?

And just to keep this all straight … at this point, don’t worry about the imp itself (the hardware device). Concentrate on the Agent. The Agent is what talks between your Android app and the imp hardware. You will be sending POST requests to the Agent URL, and the Agent will be returning back information immediately after you send it a command. The hardware part can be done after you are able to successfully converse with the Agent.

#6

See also Enforce Agent HTTPS Connections and Implement Extra Agent Security.