Web Server

Discussions on extending SharpCap using the built in Python scripting functionality
Xio1996
Posts: 42
Joined: Fri Feb 21, 2020 10:15 am
Location: Isle of Wight, UK

Web Server

#1

Post by Xio1996 »

Hi everybody,

I would like to create a simple web server in SharpCap to service remote calls from other applications in my setup.

Looking online, Python seemed to have a simple way of doing this but I have failed at the first hurdle. When I try and import the HTTPServer it tries to import socketserver, which doesn't exist. Below are the messages from the console.

Code: Select all

from http.server import HTTPServer, BaseHTTPRequestHandler
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\SharpCap 4.1 (64 bit)\PythonLib.zip\http\server.py", line 99, in <module>
ImportError: No module named 'socketserver'
I was hoping there was a way round this error?

Many thanks

Pete
User avatar
admin
Site Admin
Posts: 13350
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Web Server

#2

Post by admin »

Hi Pete,

don't know if this is the cause, but in the import it is asking for 'socketserver' (all lower case), and I can see that the file included in the library zip is 'SocketServer.py' with capital letters. Maybe that is stopping it finding the module?

The way to test would be to grab the 'Pythonlib.zip' file out of your SharpCap install directory, unzip it, rename the file, create a new PythonLib.zip and replace the old one. If that works, let me know and I will incorporate the change into the next SharpCap update.

cheers,

Robin
Jean-Francois
Posts: 402
Joined: Sun Oct 13, 2019 10:52 am
Location: Germany

Re: Web Server

#3

Post by Jean-Francois »

Hello Robin and Pete,

I tested it ... it works, I mean that no error message.
SharpCap_SocketServer.jpg
SharpCap_SocketServer.jpg (13.05 KiB) Viewed 13843 times
But the unpacking and repacking is not so easy in the SharpCap directory.
I copy the zip in a different directory, do the change and copy back.

Pete ... I'm interested to know what you want to do.
This morning I "learned" that the EAGLE4 Manager allows the connection from an external program with a "web server" command.
I'm interested for programming SharpCap for reading some information coming from the EAGLE4.

Regards,
Jean-Francois
User avatar
admin
Site Admin
Posts: 13350
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Web Server

#4

Post by admin »

Hi Jean-Francois,

thanks for the confirmation - I just tested too and the rename works. I also found that 'queue.py' is incorrectly 'Queue.py', so I will fix both in the next SC 4.1 update.

cheers,

Robin
Xio1996
Posts: 42
Joined: Fri Feb 21, 2020 10:15 am
Location: Isle of Wight, UK

Re: Web Server

#5

Post by Xio1996 »

Hi Robin, Hi Jean-Francois,

Thank you Robin. Sorry, I got caught up coding and forgot to say your solution worked. Thank you Jean-Francois for checking as well.

Why?

I use SharpCap, Stellarium and AstroPlanner, all of which have scripting built-in. However, Stellarium (via Remote Control Plugin) and AstroPlanner both have webservices exposed to access the object model or run scripts. For a while now, I have been using scripts and the web services interface to control my EAA workflow, within the individual applications. I wanted to go further and created a c# windows app to eventually orchestrate everything. From object selection in AstroPlanner and syncing the object in Stellarium to capturing the image in SharpCap and then logging the observation back in AstroPlanner and copying/attaching the stacked image to the observation. A few simple clicks, that at 3am in the morning stop my tired brain from making mistakes! :D

Currently, the UI looks like the image below (WIP).
EAAControlPanel.png
EAAControlPanel.png (24.11 KiB) Viewed 13840 times

So, I really needed a way of controlling SharpCap remotely via a webservice. It would be nice if this feature was bulit in to SharpCap. I prefer AstroPlanner's webservices interface, where via a URL I can run a specified script and pass parameters in JSON format and receive a JSON formatted response from the script. TheSky requires you to send the javascript you want to run. While a lot of other apps Cartes du Ciel, C2A, SkyTechX, Stellarium etc allow you to send commands via sockets or web get and post.

Thank you both for your help.

Have fun

Pete
Xio1996
Posts: 42
Joined: Fri Feb 21, 2020 10:15 am
Location: Isle of Wight, UK

Re: Web Server

#6

Post by Xio1996 »

Hi Jean-Francois,

I'm not sure how the Eagle interface works, but I use the Requests module to 'poke' AstroPlanner's webservices interface from SharpCap.

Code: Select all

import urllib.request	# Web module
#import urllib.response	# Web module

f = urllib.request.urlopen("http://sharpcap.com")
print(f.read())
Have fun

Pete
User avatar
admin
Site Admin
Posts: 13350
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Web Server

#7

Post by admin »

Hi Pete,

glad to hear that you got things going :)

I actually have been thinking about some sort of server component in SharpCap, although I don't really know how it might turn out yet. I put together a prototype at one point where you could use telnet to run sequencer commands (as a sort of quick-and-dirty-lets-try-something-out starting point), but it is not enabled in released versions of SharpCap.

cheers,

Robin
Xio1996
Posts: 42
Joined: Fri Feb 21, 2020 10:15 am
Location: Isle of Wight, UK

Re: Web Server

#8

Post by Xio1996 »

Hi Robin,

I'm not sure how many people use the scripting and web services of all these great astronomy products, but I really enjoy writing code to enhance my observing experience. The existence of an external interface to interact with SharpCap would be be exciting :D and beneficial. However, I bet you have a million other SharpCap enhancements on your plate.

Thank you for all your support.

Pete
Jean-Francois
Posts: 402
Joined: Sun Oct 13, 2019 10:52 am
Location: Germany

Re: Web Server

#9

Post by Jean-Francois »

Hello Pete,

I tested this afternoon. It works. I can read and change some settings of my EAGLE from the SharpCap script.

For example:

Code: Select all

>>> f = urllib.request.urlopen("http://localhost:1380/getecco")
>>> print(f.read())
>>> b'{"result":"OK", "ecco":"Connected", "temp":"25.1", "hum":"45", "dew":"26.2", "temp5":"25.3", "temp6":"25.4", "temp7":"25.5”}'
Thanks for the short help.

Regards,
Jean-Francois
metastable
Posts: 45
Joined: Thu Oct 26, 2023 1:24 am

Re: Web Server

#10

Post by metastable »

I love the idea of being able to control SharpCap from an external app, similar to stellarmate or the asiair. Has anyone made decent progress on this? I've started experimenting with making a REST server as well which I hope to make an Android app as a front end.
Post Reply