×

INDI Library v1.9.7 Released (29 Jul 2022)

Bi-monthly INDI Library released with new drivers and bug fixes.

Using NWConnection in SWIFT to communicate with INDI server

  • Posts: 39
  • Thank you received: 5
Hello INDI Coders,

I am still new to INDI. I am trying a little SWIFT app to directly communicate with an INDI server running on a Raspberry Pi.

I like to use SWIFT on macOS / iPadOS taking advantage of the still relatively new Network Framework (introduced in 2018). Apple introduced this framework to get rid of sockets and to make communication easier. While this might be debatable, I just like to know how this would work in SWIFT.

How would I send a command to an INDI server? What data format does it have to be? What is the syntax? Is there a quick and easy tutorial? I used setprop and getprop successfully from the command line in a terminal window. I do not want to import c-code or use those functions in SWIFT.

To give you a extremely basic example, I can easily connect to an INDI server on my local network with the following few code lines:
import Cocoa
import Foundation
import Network
 
let IPscope: NWEndpoint.Host = NWEndpoint.Host("192.168.68.70")
let indiPort: NWEndpoint.Port = NWEndpoint.Port(rawValue: 7624)!
 
let connection = NWConnection(host: IPscope, port: indiPort, using: .tcp)
 
connection.stateUpdateHandler = { (newState) in
    switch(newState) {
    case .ready:
        print("Network ready")
    case .waiting(let error):
        print("Network waiting .... , error: \(error.localizedDescription)")
    case .failed(let error):
        print("Network connection failed :-( .... , error: \(error.localizedDescription)")
    default:
        break
    }
}
connection.start(queue: .main)

This code seems to work.

Now how do I receive or send (i.e. change) properties?

Any help is highly appreciated.
The following user(s) said Thank You: Jasem Mutlaq
9 months 2 weeks ago #76842

Please Log in or Create an account to join the conversation.

  • Posts: 39
  • Thank you received: 5
I found these documents on the XML protocol/layer:

www.clearskyinstitute.com/INDI/

They are all from 2007.  Are they still valid?
9 months 1 week ago #77124

Please Log in or Create an account to join the conversation.

Yes it's valid. Send this to get the properties.

<getProperties version="1.7"/>

You can test with telnet as well, start indi server

indiserver -v indi_simulator_telescope

then elsewhere start telnet

telnet localhost 7624

and then you can exchange the XML messages with INDI server.
Jasem Mutlaq
Support INDI & Ekos; Get StellarMate Astrophotography Gadget.
How to Submit Logs when you have problems?
Add your observatory info
The following user(s) said Thank You: Willi
9 months 1 week ago #77126

Please Log in or Create an account to join the conversation.

  • Posts: 39
  • Thank you received: 5
Thank you! 

I got it working in XCode in a SWIFT playground.

The NWNetwork framework seems straight forward for this task. 

I have to check the timing and variable sizes, though. I don’t get all the xml response with a single receive call. 

Building a SWIFTUI around it should not be too difficult. 
9 months 1 week ago #77136

Please Log in or Create an account to join the conversation.

Time to create page: 0.473 seconds