Can I get data back to my device using HTTP?
-
I have a remote device that is using GPRS to send the data to Mango and I am using HTTP for this. It works great and has been running reliably for 6 months on trial now.
Using HTTP I am only able to send data to the Mango server but I want to be able to read settings on Mango such as ON/OFF states and time settings etc. Is this possible with an HTTP request?
I can't initiate anything from the server as the device has no visible IP address. I have considered making a permanent connection to the sever similar to how push email works and send data down that but don't see how to do this at present. I can open the connection form the device but I don't see anything in Mango that allows me to send to the device.
-
If I am following you correctly, you wish to connect to the Mango server using HTTP and read binary point values and the current time? You should be able to use the REST API for this, there isn't a endpoint for time settings but you can read the latest timestamp of a point value.
-
I want to be able to read binary and analog data. What I am trying to do is control a motor at the remote location from Mango. I also want to be able to send the speed setting (frequency) for the drive. Time stamp I don't need as I get this from the Internet.
-
So what you are proposing is to set up a virtual datapoint that you can set to 0 or 1 to start or stop the drive and another numeric datapoint which you will set to control the speed of the drive? That should work. You can poll /rest/v1/point-values/POINT_XID/latest?limit=1 to get the latest point value.
What are you going to be using to read the point value and send it to the drive?
-
Excellent Jared. That worked. I tried it in the browser and I could get the data back from Mango. Now I can code on the remote device to poll this data.
I have a custom built data logger running NETMF and this will poll the data over the GPRS connection.
-
Great. The only issue you may have is authentication, the current Mango authentication is all session cookie based. You will have to make sure your HTTP client can handle cookies. You can find the REST end points for logging in in the Swagger documentation, change your
env.properties
so thatswagger.enabled=true
and navigate to/swagger/index.html
Mango 2.8 will support token based authentication for the REST API.
-
Ah, that might be a bit of a problem. There is no cookie capability as this does not have a proper browser.
I tried it on a browser that was not logged in and sure enough, I got an access denied message.
Is it possible to use some form of API key or other method to do this?
-
Nope, at the moment session cookies are the only supported authentication mechanism. 2.8 will have token authentication.
I'm not familiar with NETMF but even if it doesn't support cookies you should be able to manually read the
Set-Cookie
header when you login and send it back in theCookie
header with each request. -
OK. I'll check out how to do this.
-
Here is a link to some documentation about how authentication works which should be helpful:
https://help.infiniteautomation.com/support/solutions/articles/14000023292-mango-rest-api-authentication -
@v8dave
Does your device support Python by chance or some other scripting language? -
Hi Woody, the unit is programmed with C# using .NET Micro Framework running a custom board with the GHI Electronics G400D module.
-
Hmmm, well the C# path may lead you somewhere. Then again, it could be down a rabbit hole I suppose.
-
I should be able to do this one I figure out how to login from the device using TCP/IP. I have a full implementation of the TCP/IP stack on this device. I can then extract the cookie and use this to send back with the request.
It's just another level of coding I need to add. At present I send HTTP without doing any logging in.