Rest API for sensor data?


I’m curious if there’s a way to get rest API sensor data in SGP. As we know, commercial cloud sensors are expensive, so I decided to see if I can get a home-brew cloud sensor via an IR temperature sensor. It’s now sitting atop my home built weather station. I can program the micro controller to return data with rest calls. I think such a thing would be helpful for the DIY types in the community. Also, the rest API functionality would include live temperature, dew point data, etc.



I guess that depends on what you’re after. If you want SGP to shutdown when it gets cloudy or starts to rain you can create an ASCOM Safety Device that polls your sensor and triggers an “Unsafe” status when SGP needs to shutdown.

If you want something that you can just push data into and get it to display in SGP then this does not exist.



Thanks for your reply Jared.

I was thinking more like a GET request, e.g. http://restServer:port/okToImage
with a return of either 1 or 0 to indicate that it’s safe or unsafe, respectively.

The server side triggers would be coded by the user. For example, in my case, I could have a threshold in my server side code that would trigger an unsafe condition if the sky IR temperature is within some threshold of the ambient temperature, indicating clouds.



So why not create an ASCOM Safety Device to access your API? The Safety Device would be pretty slim and would really just be a way for you to send back True/False to SGP. Just like you’re mentioning the “Safe To Image” status could be completely controlled via your API, the Safety Device is just acting as a known device proxy at that point.

If we added the ability to define and directly call an API in SGP it wouldn’t make much sense as the APIs could differ wildly. However if you’re writing the API interface (the Safety Device) and you’re writing the API, then you maintain control of those things and we can expect the Safety Device to act in a specific way. Win/Win!

Best of all we already support Safety Devices so if you were to quickly create one you could have it working by tomorrow :slight_smile:



Okay, sounds like a good plan. I’m willing, but trouble is I have no experience in ASCOM programming. I’ve programmed for years in other lower level languages like C and Fortran for work. Now a-days it’s python. Does anyone know a good ASCOM programming tutorial?



Developing an ASCOM driver is actual dirt simple. Especially the Safety Device.

Grab VS 2015 Community Edition
Grab the ASCOM Developer Components

There are some tutorials for ASCOM on their site:

Alternatively you can probably find an existing Safety Device online and change that. I believe @Chris posted one a while back but I’m not sure if he posted the source. Actually I believe the source for his Boltwood Safety Device gets distributed with the driver if I’m not mistaken.

I guess that’s a 2nd path you could take. Have some script that queries your device and writes a Boltwood formatted “one line” file. Then use Chris’ Boltwood Safety Device to monitor that file.

If you do end up writing your own device I’d recommend RestSharp to handle the HTTP request and NewtonSoft’s JSON Deserializer library (although it may be adequate to just do a string compare on the actual JSON rather than serializing it into an object)



To add to Jared’s excellent suggestions:

Use C# rather than VB.NET. Most of the tutorials and source code uses this. Going from C to C# shouldn’t be difficult. Whatever you do don’t try using C or C++ directly COM interfaces are very difficult with these.

In addition to the sources that Jared mentioned there are the ASCOM platform sources on SourceForge. DriversandSimulators\OpenWeatherMap has an Observing conditions driver that reads JSON using JavaScriptSerialiser. That may give you a few ideas.



Excellent! Thanks guys. Very helpful suggestions.