Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Dwarf II TCP server

**NOTE: This is a work in progress. It's been cloudy, so I haven't tested this code yet.**

This software lets you send goto commands to the Dwarf II using Stellarium's Telescope Control.

Requires:
Expand All @@ -22,15 +20,28 @@ This software setups up a TCP server. When you select an object Stellarium, and

3. Install libraries

On Linux, Mac or WSL for Windows :

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code also works on MacOS.

On Linux, Mac,  or WSL for Windows

```
pip install -r requirements.txt
```

On Windows :

you can install Python 3.11 (search on Microsoft Store)
open a command prompt on the directory and do :

```
python3 -m pip install -r requirements.txt
```

4. Copy `config.sample.py`, and rename it to `config.py`.

The `HOST` and `PORT` should be the same as those used in Stellarium Telescope Plugin.

Fill in your `LATITUDE` and `LONGITUDE`.
Fill in your `LATITUDE` and `LONGITUDE` (LONGITUDE is negative west of Greenwich)

Add also your `TIMEZONE`, it's need when you are using the Stellarium Mobile App

Copy link
Member

@wykhuh wykhuh Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think end users should enter in the correct sign, and this app will reverse the sign and send the reverse sign to the API. If the DwarfLabs devs fix the API, then we can remove the code in the app that reverses the sign.

If you are using the Dwarf wifi, the `DWARF_IP` is 192.168.88.1. If you are using Dwarf II in STA mode, then get the IP for your Dwarf II.

Expand All @@ -43,4 +54,16 @@ If you are using the Dwarf wifi, the `DWARF_IP` is 192.168.88.1. If you are usin
python server.py
```

6. Select an object in Stellarium, and issue a slew command. The Dwarf II should move to that object.
On Windows :

```
python3 server.py
```

6. Start the dwarf II and use the mobile app and go to Astro Mode and do the calibration

7. Select an object in Stellarium, and issue a slew command. (shortcut for Windows is Alt + number, See Stellarium documentation, Command + number for Mac). The Dwarf II should move to that object.

8. You can also use the Stellarium Plus Mobile App with the remote Telescopte function, Select an object in Stellarium, and issue a goto command with the remote control. The Dwarf II should move to that object.

**NOTE: If the server disconnects from Stellarium, You can try reconnect on the cmd window by typing Y otherwise the program will stop **
1 change: 1 addition & 0 deletions config.sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
LATITUDE = 0
LONGITUDE = 0
DWARF_IP = "192.168.88.1"
TIME_ZONE="Europe/Paris"
DEBUG = True
11 changes: 7 additions & 4 deletions lib/dwarfII_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ def ws_uri(dwarf_ip):
return f"ws://{dwarf_ip}:9900"


def now():
return str(datetime.datetime.now()).split(".")[0]
def nowUTC():
return str(datetime.datetime.utcnow()).split(".")[0]


def nowLocalFileName():
return datetime.datetime.today().strftime('%Y%m%d%H%M%S')

def goto_target(latitude, longitude, rightAscension, declination, planet=None):
options = {
"interface": startGotoCmd,
"camId": telephotoCamera,
"lon": longitude,
"lat": latitude,
"date": now(),
"path": "DWARF_GOTO_timestamp",
"date": nowUTC(),
"path": "DWARF_GOTO_" + nowLocalFileName(),
}

if planet is not None:
Expand Down
15 changes: 11 additions & 4 deletions lib/dwarf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@
import lib.my_logger as log


def perform_goto(ra, dec):
payload = d2.goto_target(config.LATITUDE, config.LONGITUDE, ra, dec)
def perform_goto(ra, dec, result_queue):
# Inverse LONGITUDE for DwarfII !!!!!!!
payload = d2.goto_target(config.LATITUDE, - config.LONGITUDE, ra, dec)

response = connect_socket(payload)

if response["interface"] == payload["interface"]:
if response:

if response["interface"] == payload["interface"]:
if response["code"] == 0:
log.debug("Goto success")
result_queue.put("ok")
return "ok"
elif response["code"] == -45:
log.error("Target below horizon")
elif response["code"] == -46:
log.error("Goto or correction bump limit")
else:
log.error("Error:", response)
else:
else:
log.error("Dwarf API:", response)
else:
log.error("Dwarf API:", "Dwarf II not connected")

result_queue.put(False)

def perform_camera_status():
payload = d2.cameraWorkingState()
Expand Down
54 changes: 41 additions & 13 deletions lib/stellarium_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import lib.my_logger as my_logger


def process_ra_dec_int(ra_int, dec_int):
h = ra_int
d = math.floor(0.5 + dec_int * (360 * 3600 * 1000 / 4294967296.0))
Expand Down Expand Up @@ -45,6 +44,21 @@ def process_ra_dec_int(ra_int, dec_int):
},
}

def process_ra_dec(ra_int, dec_int):
data = process_ra_dec_int(ra_int, dec_int)
ra = data["ra"]
dec = data["dec"]
ra_number = ra['hour'] + ra['minute'] / 60 + ra['second'] / 3600
if dec_int >= 0:
dec_number = dec['degree'] + dec['minute'] / 60 + dec['second'] / 3600
else:
dec_number = -(dec['degree'] + dec['minute'] / 60 + dec['second'] / 3600)

return {
"ra_number": ra_number,
"dec_number": dec_number
}


def format_ra_dec(ra_int, dec_int):
data = process_ra_dec_int(ra_int, dec_int)
Expand All @@ -59,20 +73,34 @@ def format_ra_dec(ra_int, dec_int):


def process_stellarium_data(raw_data):
data = struct.unpack("3iIi", raw_data)
my_logger.debug("data from Stellarium >>", data)
my_logger.debug("data from Stellarium >>", raw_data)
try:
data = struct.unpack("3iIi", raw_data)
my_logger.debug("data from Stellarium >>", data)

ra_int = data[3]
dec_int = data[4]
formatted_data = format_ra_dec(ra_int, dec_int)
my_logger.debug("ra: " + formatted_data["ra"] + ", dec: " + formatted_data["dec"])
ra_int = data[3]
dec_int = data[4]
formatted_data = format_ra_dec(ra_int, dec_int)
my_logger.debug("ra: " + formatted_data["ra"] + ", dec: " + formatted_data["dec"])

return {
"ra_int": ra_int,
"ra": formatted_data["ra"],
"dec_int": dec_int,
"dec": formatted_data["dec"],
}
data_number = process_ra_dec(ra_int, dec_int)
ra_number = data_number["ra_number"]
dec_number = data_number["dec_number"]
my_logger.debug("ra: " + f"{ra_number}" + ", dec: " + f"{dec_number}")

return {
"ra_int": ra_int,
"ra": formatted_data["ra"],
"ra_number": ra_number,
"dec_int": dec_int,
"dec": formatted_data["dec"],
"dec_number": dec_number,
}

except struct.error:
# If a struct.error occurs, the data is not in the expected structure format
my_logger.debug("data from Stellarium Mobile >>", raw_data)
return False


def update_stellarium(ra_int, dec_int, connection):
Expand Down
1 change: 1 addition & 0 deletions lib/websockets_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ def connect_socket(payload):
return json.loads(message)
except TimeoutError:
my_logger.error("Could not connect to websocket")
return False
Loading