Jump to content

[1.8.x to 1.12.x] kRPC: Remote Procedure Call Server (v0.5.1, 2nd March 2023)


djungelorm

Recommended Posts

On 27/01/2018 at 10:18 PM, CptMichles700 said:

Hello.

On the KRPC documentation website, it states that the Node JS client requires using v0.4.0.

  1. Is this still true? The last update to the Node JS client was quite a while ago.
  2. Do you know what why? What is the Node JS client lacking?

Thanks.

It requires v0.4.0 (or above) as the websockets communication protocol it uses was added in v0.4.0.

As for compatibility with the latest v0.4.4 - it should mostly work. The things that won't are any RPCs that are new or have changed since v0.4.0. Specifically these files will need regenerating: https://github.com/eXigentCoder/krpc-node/tree/master/lib/services Another thing that won't work is setting rates for streams, which will probably require code changes in the client.

I'm not the maintainer of that project, but will have a look into updating it and will open a pull request.

Link to comment
Share on other sites

9 hours ago, KerbalX said:

I have just installed the v0.4.4 c++ and ran into an error.

it says: 'krpc/event.hpp' file not found space_center.hpp 

@djungelormcan you help me with this? Thanks. 

Oops - some files were missing from the configure script! Should be fixed in this release: https://github.com/krpc/krpc/releases/tag/v0.4.4.post1

Link to comment
Share on other sites

On 1/29/2018 at 5:00 PM, djungelorm said:

It requires v0.4.0 (or above) as the websockets communication protocol it uses was added in v0.4.0.

As for compatibility with the latest v0.4.4 - it should mostly work. The things that won't are any RPCs that are new or have changed since v0.4.0. Specifically these files will need regenerating: https://github.com/eXigentCoder/krpc-node/tree/master/lib/services Another thing that won't work is setting rates for streams, which will probably require code changes in the client.

I'm not the maintainer of that project, but will have a look into updating it and will open a pull request.

Thank you. I ask because it was not working for me. Turns  out, you must switch from "TCP" to "Websockts" in the KRPC menu in Kerbal.

I was also considering forking krpc-node and modifying it to make some of the operations to sync instead of async to avoid having chain functions to get anything done.

Link to comment
Share on other sites

4 hours ago, CptMichles700 said:

Thank you. I ask because it was not working for me. Turns  out, you must switch from "TCP" to "Websockts" in the KRPC menu in Kerbal.

I was also considering forking krpc-node and modifying it to make some of the operations to sync instead of async to avoid having chain functions to get anything done.

Ah yes forgot to mention that! Yes you need to start the server using websockets.

I've made a pull request on the krpc-node repository to update it with the new features in v0.4.4: https://github.com/eXigentCoder/krpc-node/pull/5

async is nice to have for passing success/error handlers, but I agree can be quite cumbersome at times. I think it would be good if the library supported both styles? Maybe the call could behave in a synchronous manner if the callback is undefined.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
On 2.2.2018 at 10:18 PM, djungelorm said:

Ah yes forgot to mention that! Yes you need to start the server using websockets.

I've made a pull request on the krpc-node repository to update it with the new features in v0.4.4: https://github.com/eXigentCoder/krpc-node/pull/5

async is nice to have for passing success/error handlers, but I agree can be quite cumbersome at times. I think it would be good if the library supported both styles? Maybe the call could behave in a synchronous manner if the callback is undefined.

Quite a while ago, I forced myself into using async/await by rewriting the entire krpc-node library into this: https://github.com/lucaelin/krpc.js

I was able to get things running in the browser and implemented dynamic service generation as well, but I simply do not have enough spare time to get the quality of this repo up... non of the tests are working at the moment, and there are quite some bugs.. I would be really happy if someone could help me out on this!

Cheers!

Edited by lucaelin
Link to comment
Share on other sites

4 hours ago, lucaelin said:

Quite a while ago, I forced myself into using async/await by rewriting the entire krpc-node library into this: https://github.com/lucaelin/krpc.js

I was able to get things running in the browser and implemented dynamic service generation as well, but I simply do not have enough spare time to get the quality of this repo up... non of the tests are working at the moment, and there are quite some bugs.. I would be really happy if someone could help me out on this!

Cheers!

I managed to do something similar but without rewriting the whole thing. I just made all the calls return a promise instead of work off callbacks and then went from there.
I'll check out your repo. Mabey its a step forward. I feel the current NodeJS KRPC library is to low level and hard to use, mainly because It lacks structure(hierarchy) of objects but this could be fixed by changing how the services files are generated.

Link to comment
Share on other sites

On 2/20/2018 at 6:10 AM, lucaelin said:

Quite a while ago, I forced myself into using async/await by rewriting the entire krpc-node library into this: https://github.com/lucaelin/krpc.js

I was able to get things running in the browser and implemented dynamic service generation as well, but I simply do not have enough spare time to get the quality of this repo up... non of the tests are working at the moment, and there are quite some bugs.. I would be really happy if someone could help me out on this!

Cheers!

The structure is nice as well as the async feature. Being able to call

vessel.autopilot.sas = true

is much easier then doing  something like

autopilotId = getVesselAutoPIlot(vesselId)

I'm going to see if the original owner of krpc-node would be interested in implementing such a structure in his library, given that krpc-node already has tests and is already established. Though his library generates the services before run time so that will be interesting.

Edited by CptMichles700
Link to comment
Share on other sites

  • 2 weeks later...
On 11/02/2018 at 9:32 AM, funkheld said:

Hi good afternoon.
How can you use laserdist with krpc?

 

greeting

Sorry for the incredibly slow reply.... been a bit too busy IRL recently!

You can use laserdist in same way you can from kOS - by interacting with the part modules, getting fields and calling actions. The kRPC documentation for this is here: http://krpc.github.io/krpc/python/api/space-center/parts.html#module

If you want I can also try coding up an example - let me know if that'd be useful.

Link to comment
Share on other sites

I'm new to programming with kRPC and am working on a program that uses the TCP/IP sockets interface to communicate with kRPC (my goal is to make a mobile app that can interact with kRPC using just sockets with no other dependencies). To learn how to use the protocol, I'm using Python on my Windows PC and KSP 1.3, following the examples in the documentation. I'm able to connect and get the KRPC.GetStatus command to work, but am having problems getting the UI.Message command to work. Here's the code I'm trying to use:

import socket
from time import sleep
from google.protobuf.internal.encoder import _VarintEncoder
from google.protobuf.internal.decoder import _DecodeVarint
from krpc.schema import KRPC_pb2 as KRPC

"""
support functions (e.g. send_message()) omitted for clarity -- see kRPC documents for examples.
"""

# connect over socket to kRPC, request status
call = KRPC.ProcedureCall()
call.service = 'KRPC'
call.procedure = 'GetStatus'
request = KRPC.Request()
request.calls.extend([call])
send_message(rpc_conn, request)

# Receive the response
response = recv_message(rpc_conn, KRPC.Response)

# Check for an error in the response
if response.HasField('error'):
    raise RuntimeError('ERROR: ' + str(response.error))

# Check for an error in the results
assert(len(response.results) == 1)
if response.results[0].HasField('error'):
    raise RuntimeError('ERROR: ' + str(response.error))

# Decode the return value as a Status message
status = KRPC.Status()
status.ParseFromString(response.results[0].value)

# Test UI.Message()
print 'Invoking UI.Message'
call = KRPC.ProcedureCall()
call.service = 'UI'
call.procedure = 'Message'

arg = KRPC.Argument()
arg.position = 0
arg.value = 'nice ship you have there'
call.arguments.extend([arg])

request = KRPC.Request()
request.calls.extend([call])
send_message(rpc_conn, request)

# Receive the response 
response = recv_message(rpc_conn, KRPC.Response) 

# Check for an error in the response
if response.HasField('error'):
    raise RuntimeError('ERROR: ' + str(response.error))

# Check for an error in the response
assert(len(response.results) == 1)
if response.results[0].HasField('error'):
    raise RuntimeError('ERROR: ' + str(response.error))

I'm guessing that I'm not initializing the arguments to UI.Message properly? I don't get any errors or any response from kRPC after the initial response from the GetStatus command. Thanks for any help!

Link to comment
Share on other sites

On 3/15/2018 at 10:39 PM, ByteArts said:

I'm new to programming with kRPC and am working on a program that uses the TCP/IP sockets interface to communicate with kRPC (my goal is to make a mobile app that can interact with kRPC using just sockets with no other dependencies). To learn how to use the protocol, I'm using Python on my Windows PC and KSP 1.3, following the examples in the documentation. I'm able to connect and get the KRPC.GetStatus command to work, but am having problems getting the UI.Message command to work. Here's the code I'm trying to use:


import socket
from time import sleep
from google.protobuf.internal.encoder import _VarintEncoder
from google.protobuf.internal.decoder import _DecodeVarint
from krpc.schema import KRPC_pb2 as KRPC

"""
support functions (e.g. send_message()) omitted for clarity -- see kRPC documents for examples.
"""

# connect over socket to kRPC, request status
call = KRPC.ProcedureCall()
call.service = 'KRPC'
call.procedure = 'GetStatus'
request = KRPC.Request()
request.calls.extend([call])
send_message(rpc_conn, request)

# Receive the response
response = recv_message(rpc_conn, KRPC.Response)

# Check for an error in the response
if response.HasField('error'):
    raise RuntimeError('ERROR: ' + str(response.error))

# Check for an error in the results
assert(len(response.results) == 1)
if response.results[0].HasField('error'):
    raise RuntimeError('ERROR: ' + str(response.error))

# Decode the return value as a Status message
status = KRPC.Status()
status.ParseFromString(response.results[0].value)

# Test UI.Message()
print 'Invoking UI.Message'
call = KRPC.ProcedureCall()
call.service = 'UI'
call.procedure = 'Message'

arg = KRPC.Argument()
arg.position = 0
arg.value = 'nice ship you have there'
call.arguments.extend([arg])

request = KRPC.Request()
request.calls.extend([call])
send_message(rpc_conn, request)

# Receive the response 
response = recv_message(rpc_conn, KRPC.Response) 

# Check for an error in the response
if response.HasField('error'):
    raise RuntimeError('ERROR: ' + str(response.error))

# Check for an error in the response
assert(len(response.results) == 1)
if response.results[0].HasField('error'):
    raise RuntimeError('ERROR: ' + str(response.error))

I'm guessing that I'm not initializing the arguments to UI.Message properly? I don't get any errors or any response from kRPC after the initial response from the GetStatus command. Thanks for any help!

Looks like you weren't encoding the string correctly. It needs to be converted to a binary string and then prepended with its length (encoded as a varint). Here's the updated code that works for me: https://gist.github.com/djungelorm/1e3925e4edc4011b71439b87f8b4a665

Link to comment
Share on other sites

On 3/17/2018 at 5:14 AM, djungelorm said:

Looks like you weren't encoding the string correctly. It needs to be converted to a binary string and then prepended with its length (encoded as a varint). Here's the updated code that works for me: https://gist.github.com/djungelorm/1e3925e4edc4011b71439b87f8b4a665

Thanks so much! That makes sense. I was thinking that SerializeToString() in send_message() took care of that, but obviously I was wrong. Protocol buffers are a pretty powerful and flexible mechanism, but can be quite complicated to debug when something isn't working!

Link to comment
Share on other sites

  • 3 weeks later...
On 4/5/2018 at 1:25 AM, FleshJeb said:

Is it possible to get KRPC to expose the per-part drag values, like it's able to do with the thermals?

ex. https://krpc.github.io/krpc/python/api/space-center/parts.html#SpaceCenter.Part.thermal_conduction_flux

This isn't currently possible, but I'll try and add it in the next release. I've added an issue on github to track it here: https://github.com/krpc/krpc/issues/459

Link to comment
Share on other sites

  • 1 month later...

When I try to "import krpc" in Python I get this:

Quote

Traceback (most recent call last):
  File "D:\Python\KSP\045test.py", line 1, in <module>
    import krpc
  File "C:\Python\lib\site-packages\krpc\__init__.py", line 1, in <module>
    from krpc.connection import Connection
  File "C:\Python\lib\site-packages\krpc\connection.py", line 3, in <module>
    from krpc.encoder import Encoder
  File "C:\Python\lib\site-packages\krpc\encoder.py", line 8, in <module>
    import krpc.schema.KRPC_pb2 as KRPC
  File "C:\Python\lib\site-packages\krpc\schema\KRPC_pb2.py", line 191, in <module>
    options=None, file=DESCRIPTOR),
TypeError: __init__() got an unexpected keyword argument 'file'

Any ideas what's wrong?

Edited by Nathanson
Link to comment
Share on other sites

16 hours ago, Nathanson said:

When I try to "import krpc" in Python I get this:

Any ideas what's wrong?

Probably because your installed protobuf version is too old? Try running the following script to see what version of protobuf you have:

import google.protobuf
print(google.protobuf.__version__)

You need version 3.2.0 or higher.

You can update it by running pip from a command line:

pip install protobuf --upgrade

 

Link to comment
Share on other sites

  • 2 weeks later...

kRPC with kRPCmj

I know this is the kRPC thread,  But @artwhaley didn't create one (that I can find) and it is a mod for a mod, with the mod's documentation linking to the mod's mod... So maybe I can get some help with the mod's mod here?

 

I will get some of the formalities out of the way before the question:

 

KSP 1.4.3

Mech Jeb 2 (Current release version, not the Dev build #800)

kRPC (Current Version)

 

log>>> https://www.dropbox.com/s/wlm1r4lqofv7jxx/KSP.log?dl=0

Screenshot>>> qhfumgt.png

(The error I am going to refer to is the top box / error message)

(kRPC works in 1.4.3, I just have gotten used the incompatibility detected warning)

 

 

For installation as stated here:

https://github.com/artwhaley/krpcmj/wiki

 

When I put the krpcmj.dll into the kRPC folder I get this error (pictured in the screenshot)

I have tried every configuration of how to install this mod in order to NOT get this error. to include the GameData folder ect... ect...

 

I am doing something wrong on installation or, this project is abandoned and no longer keeping step with kRPC/ Mech Jeb, or I am not using the correct version of KSP for this to work? Or I have completely missed the mark and it is something else?

 

TL;DR (Below) I am new to coding and just want to do more than leave the launch pad until I get better.

Don't get me wrong, I would love to write an auto_pilot code that would allow me to not have to use MJ. But I am new to programming ( 3 almost 4 months now ) kRPC keeps me motivated to keep writing code (and have fun doing it, I am playing an awesome game after all)  the more I write the more I learn and the better I get at writing, so I am using this as a learning tool, But you know... It would also be nice to dock with something or use it to really nail down an ascent profile or something... It gets boring going to orbit, coming back, going to orbit, coming back, going to orbit, coming back... I still want to enjoy the game a bit sometimes...

 

Edited by Space_Kadet
Link to comment
Share on other sites

On 5/29/2018 at 2:51 AM, Keith Young said:

How would we download all old versions of your mod?

They're all available on the github releases page: https://github.com/krpc/krpc/releases

On 5/30/2018 at 2:07 AM, ByteArts said:

Anyone know what the "Debug logging" option in the kRPC configuration dialog does and how to use it? I was hoping to watch the calls I'm making to see if I'm sending the data right.

Thanks,
Scott

Enabling that makes the logging more verbose in KSPs player.log file. These logs aren't viewable in game, but can been in that text log file. It can be found in the following location (which depends on your operating system):

  • Windows: KSP_win\KSP_Data\output_log.txt (32bit) or KSP_win64\KSP_x64_Data\output_log.txt (64bit) or %USERPROFILE%\AppData\LocalLow\Squad\Kerbal Space Program\output_log.txt
  • Mac OS X: Open Console, on the left side of the window there is a menu that says 'files'. Scroll down the list and find the Unity drop down, under Unity there will be Player.log ( Files>~/Library/Logs>Unity>Player.log )
  • Linux: ~/.config/unity3d/Squad/Kerbal\ Space\ Program/Player.log

More details here: https://docs.unity3d.com/Manual/LogFiles.html

The debug logging is only really useful if you are designing your own client library.

Link to comment
Share on other sites

On 5/30/2018 at 2:39 AM, Space_Kadet said:

kRPC with kRPCmj

I know this is the kRPC thread,  But @artwhaley didn't create one (that I can find) and it is a mod for a mod, with the mod's documentation linking to the mod's mod... So maybe I can get some help with the mod's mod here?

 

I will get some of the formalities out of the way before the question:

 

KSP 1.4.3

Mech Jeb 2 (Current release version, not the Dev build #800)

kRPC (Current Version)

 

log>>> https://www.dropbox.com/s/wlm1r4lqofv7jxx/KSP.log?dl=0

Screenshot>>> qhfumgt.png

(The error I am going to refer to is the top box / error message)

(kRPC works in 1.4.3, I just have gotten used the incompatibility detected warning)

 

 

For installation as stated here:

https://github.com/artwhaley/krpcmj/wiki

 

When I put the krpcmj.dll into the kRPC folder I get this error (pictured in the screenshot)

I have tried every configuration of how to install this mod in order to NOT get this error. to include the GameData folder ect... ect...

 

I am doing something wrong on installation or, this project is abandoned and no longer keeping step with kRPC/ Mech Jeb, or I am not using the correct version of KSP for this to work? Or I have completely missed the mark and it is something else?

 

TL;DR (Below) I am new to coding and just want to do more than leave the launch pad until I get better.

Don't get me wrong, I would love to write an auto_pilot code that would allow me to not have to use MJ. But I am new to programming ( 3 almost 4 months now ) kRPC keeps me motivated to keep writing code (and have fun doing it, I am playing an awesome game after all)  the more I write the more I learn and the better I get at writing, so I am using this as a learning tool, But you know... It would also be nice to dock with something or use it to really nail down an ascent profile or something... It gets boring going to orbit, coming back, going to orbit, coming back, going to orbit, coming back... I still want to enjoy the game a bit sometimes...

 

I submitted a pull request on the krpcmj project a while ago (https://github.com/artwhaley/krpcmj/pull/4). It got merged, but the DLL in the repository was never updated.

In the meantime, you can download a copy of the DLL built with the patch from here: https://www.dropbox.com/s/6vbrugddsf5vknn/krpcmj.dll?dl=0

Also that log file you posted doesn't actually help. Confusingly there are two log files with KSP. The player.log probably has the illuminating error messages in it... See above for where to find it.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...