IPyServer

This server class is used to run IPyDriver instances and can also run executable, possibly non-python, drivers written by other parties. It creates a listening INDI service. It provides the snooping ability between drivers, enables connections to other remote INDI servers so a branching tree network of drivers can be made, it implements enableBLOB instructions received from the client, and allows up to ten client connections.

If only executable drivers or remote servers are being used, and no IPyDriver instances are implemented, no drivers should be set.

class IPyServer(*drivers, host='localhost', port=7624, maxconnections=5)

Once an instance of this class is created, the asyncrun method should be awaited which will open a port, and the INDI service will be available for clients to connect.

drivers are IPyDriver objects this driver handles, host and port are “localhost” and 7624 as default

maxconnections is the number of simultaneous client connections accepted, with a default of 5. The number given should be between 1 and 10 inclusive.

If, prior to asyncrun being awaited, the add_remote method is called, then a connection will be made to a remote INDI server and any of its drivers.

The add_remote method can be called multiple times to create connections to different servers making a branching tree of servers and drivers.

The add_exdriver method can be called to run an executable driver and this server will communicate to it by stdin, stdout and stderr, therefore ipyserver can act as a general INDI server for third party drivers as well as ipydriver instances.

add_exdriver(program, *args, debug_enable=False)

Adds an executable driver program, runs it and communicates to it via stdin, stdout and stderr. Then serves the driver, and any others added, by the listening port. args is used for the program arguments if any. Any program output on stderr will be logged at level ERROR.

If debug_enable is True, then DEBUG level logging will record xml traffic, if False, the xml traffic will not be logged. This can be used to prevent multiple drivers all logging xml traffic together.

add_remote(host, port, blob_enable=False, debug_enable=False)

Adds a connection to a remote server. blob_enable can be True or False. If True BLOBs and other vectors can all be sent. If False, then BLOB traffic will not pass over this link.

If debug_enable is True, then DEBUG level logging will record xml traffic, if False, the xml traffic will not be logged. This can be used to prevent multiple such connections all logging xml traffic together.

async asyncrun()

await this to operate the server together with its drivers and any remote connections.

async send_message(message, timestamp=None)

Send system wide message, timestamp should normally not be set, if given, it should be a datetime.datetime object with tz set to timezone.utc

shutdown(shutdownmessage='')

Shuts down the server, sets the flag self._stop to True and sends shutdownmessage to logger.error if given

The server has attributes:

self.host - the host

self.port - the port

self.stop - This is set to True when the server.shutdown() method is called.

self.stopped - An asyncio.Event() object, await server.stopped.wait() will block until the server stops.

self.debug_enable - Default True, will enable server xml traffic to be logged, if logging is set at DEBUG level.

add_remote

The IPyServer class has method add_remote which can make a connection to a remote INDI service and its drivers.

A typical layout might be:

../_images/rem1.png

The device traffic is broadcast along all links, so a client connected to any server can control all devices, and any of the drivers can ‘snoop’ on any other.

Great care must be taken not to introduce a network loop, otherwise traffic would circulate.

Another layout might be:

../_images/rem2.png

add_exdriver

The IPyServer class has method add_exdriver which given an executable command, will run the given driver program, and communicate with it via stdnin, stdout and stderr.

This example shows two INDI drivers available from indilib.org and both being served. No IPyDriver instances are passed into the IPyServer arguments here, however if required IPyDriver and executable drivers could all be served together:

import asyncio

from indipydriver import IPyServer

server = IPyServer(host="localhost",
                   port=7624,
                   maxconnections=5)

server.add_exdriver("indi_simulator_telescope")
server.add_exdriver("indi_simulator_ccd")
asyncio.run(server.asyncrun())

For further information regarding indilib.org see References.

Connecting using indipyclient gives:

../_images/exdrivers.png