This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Openplotter, Pypilot and Autohelm 1000
#1
Hi all,

I'm rebuilding an Autohelm1000 that died on me during a stormy passage using Pypilot. Yesterday i got my Pypilot motordriver in the mail I hooked it up using a Arduino USB-UART converter (this one). Everything works like a charm, at least at my desk.

Now I'm wondering how can i get the buttons [+1] [-1] [+10] [-10] [AUTO/STANDBY] on the Autohelm to interact with the Pypilot Openplotter app. I read in another post that the RPI-GPIO pins can be hooked up. But wouldn't it be easier to just read the buttons in the Autohelm and transfer them via UDP/TCP/Serial to the RPI Pypilot frontend app.

I have them read with a ESP32 device and transferred to SignalK with a SensESP application, I guess i can write a piece of code that writes to the GPIO pins but that seems a bit like a massive detour. Also the pins are kind a inaccessible due to the MacArthur hat.

In another old post (from 2020) i read that these AP commands are passed through a socket. Can I use that socket? 

Another related question: are XTR, VMG etc. sentences past trough to SignalK if the AP is following a route (can't test that at my desk.   Tongue)

Thanks for your input,

Koen.
Reply
#2
Hi again,

I did some more digging ...
   
Shows me that a TCP port nr. 23322 is monitored by Python. Since I found a forum post where Sean says that AP commands are sent trough 21311, I guessed: maybe keyboard error?!

So I started my good ol' friend WireShark and monitored that port ... and what do you know:
     
A message is  sent from 23322 -> 51036 with about all AP Client settings in the message body, I can't make to much about the first 34 bytes (TCP/IP header), but from then on, the message can be easily understood. 
51036 promptly replies with:
     
66 bytes of "Can't make to much of it". However those bytes are the TCP/IP header and an acknowledgement of previous received data.
Also I read in a forum post that pypilot_lcd.py script clearly shows how the input from the Pypilot control panel:
   
Is transferred over wireless to the pypilot application. That is exactly what i need! But I just can't find the source code. Can I get some pointers here?

Kind regards,

Koen.

BTW. completely unrelated but i do not want to start yet another new thread: 
   
I have a serial conflict on my GPS, it is connected to GPSD, but other settings also generate the conflict warning.
Reply
#3
Looks like i'm making a habit of replying to my own question ... I'm making progress here;

Found this manual. In it this passage ...

Quote:Pypilot has it's own data format used internally but also to communicate with remote programs. For example the OpenCPN pypilot plugin communicates using this format. The tcp port used is 23322 and the format is a simple key=value for assigning or retrieving data. To get or watch a particular key you would send watch={"key":0} or replace 0 with the period.

So I wrote a small and super simple Python script to retrieve a setting from TCP port 23322:
Code:
import socket, time

# create an INET, STREAMing socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 23322))

msg = bytes('watch={"ap.heading:."}\n'.encode())

print(s.send(msg), "bytes sent")
time.sleep(.1)

indata = s.recv(1024)
print(indata)

I guess i should be glad, the server honored me with a swift reply, albeit:

Code:
>>>
  23 bytes sent
  invalid request: watch={"ap.heading:."}\n'
>>>

A small modification trying to write to this key returns: "ap.heading is not writable".

So i reckon it is down to using the correct keys, anyone know where I can find those?

Koen.

Edit:
Don't I feel stupid, the keys are hidden in plain sight:
   
Also reading is exactly as described in the Pypilot manual, but you may NOT replace the value with a period.
Code:
msg = bytes("watch={\"ap.heading:0\"}\n".encode())
Is the correct way to ask for the current heading. Writing to writable keys is as simple as:
Code:
msg = bytes("ap.enabled=true\n".encode())
Wouldn't it be great if all questions were answered ... alas, i still need the keys for +1, +10, -1, -10 and those are not hidden in plain sight. Somebody? Anybody?

Again an edit:

When the AP is enabled the +10 +1 -1 and -10 buttons are handled by the ap.heading_command. When the ap is disabled the command to be used is servo.command=x where x is -any_number (1), 0 or +any_number (1). The space in between the +/-1 and  0 values is determined by the button used. 
For example:
Code:
msg = bytes("servo.command=1\n".encode())
print(s.send(msg), "bytes sent")
time.sleep(.2)
msg = bytes("servo.command=0\n".encode())
print(s.send(msg), "bytes sent")

Come to think of it, very straightforward. Congratulations to the developers, this was a joy to reverse engineer. (Really, NOT kidding. It was fun) I'll post the code for the ESP8266 microcontroller, a schematic and some pics when i'm done with the installation.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)