joeherwig Posted September 24, 2022 Report Posted September 24, 2022 @Paul HentyIs it true that the Websocket Server is only able to register the ports on the hostname if it is started as Admin? If not started as admin i get the "access denied" message...
Paul Henty Posted September 25, 2022 Report Posted September 25, 2022 Partly true. Certain URLs and Ports are secured by Windows. To use them, the account the application is running under needs permission. You can achieve this is two ways: 1. By running the application as Admin. 2. By giving the required permission to the current user. This is done using the following command: (You can execute this in the command window or in code using a process): netsh http add urlacl url=[URL TO REGISTER] user=[DOMAIN]\[USER OR GROUP] e.g. my PC here is call PJH. My user name is Paul. If I want to use the URL http://PJH:2048/fsuipc I would need this command: netsh http add urlacl url=http://PJH:2048/fsuipc/ user=PJH\Paul To run this command you need to be running 'as admin'. But once you've given permissions the socket server will be able to work without admin privileges. Paul 1 1
Manuel Lence Posted September 28, 2022 Report Posted September 28, 2022 Paul just updated my WEBSOCKET. Spectacular! Thanks a lot!! 1
ciccio85 Posted January 29, 2023 Report Posted January 29, 2023 (edited) Hello. Any idea on how to achieve a client using python? I tried a simple script but it does not work: import json import websocket from websocket import create_connection websocket.enableTrace(True) ws = create_connection("ws://MYIP:8384/fsuipc/") ws.send(json.dumps({"command":"about.read", "name":"about"})) result = ws.recv() print (result) ws.close() If I try that I get this response: --- request header --- GET /fsuipc/ HTTP/1.1 Upgrade: websocket Host: MYIP:8384 Origin: MYIP:8384 Sec-WebSocket-Key: nMbaFYGREah5M2uVaWU/nA== Sec-WebSocket-Version: 13 Connection: Upgrade ----------------------- --- response header --- Any suggestion? Thank you Francesco Edited January 29, 2023 by ciccio85
Paul Henty Posted January 30, 2023 Report Posted January 30, 2023 I've never used Python so I don't think I can help much. However, the response you're getting back is from the connection request: ws = create_connection("ws://MYIP:8384/fsuipc/") Maybe you need to get that response first, then send your 'about' command and get the response from that: import json import websocket from websocket import create_connection websocket.enableTrace(True) ws = create_connection("ws://MYIP:8384/fsuipc/") result = ws.recv() print (result) ws.send(json.dumps({"command":"about.read", "name":"about"})) result = ws.recv() print (result) ws.close() Paul
ciccio85 Posted January 31, 2023 Report Posted January 31, 2023 (edited) Hello, the trick was to add the fsuipc protocol. Here the working script: import json import websocket from websocket import create_connection websocket.enableTrace(True) ws = create_connection("ws://MYIP/fsuipc/", subprotocols=["fsuipc"]) ws.send(json.dumps({"command":"about.read", "name":"about"})) result = ws.recv() print (result) ws.close() Edited January 31, 2023 by ciccio85 1
Paul Henty Posted January 31, 2023 Report Posted January 31, 2023 Excellent. I'm happy you got it working. Paul
ciccio85 Posted February 5, 2023 Report Posted February 5, 2023 I have a complete working example that can be used to get the data using Python 3: import websocket import _thread import json import time import rel def on_message(ws, message): print(message) def on_error(ws, error): print(error) def on_close(ws, close_status_code, close_msg): print("### closed ###") def on_open(ws): print("Opened connection") request = { "command": "about.read", "name": "about" } request2 = { "command": "offsets.declare", "name": "myOffsets", "offsets": [ {"name": "altitude", "address": 0x0570, "type": "int", "size": 8}, {"name": "avionicsMaster", "address": 0x2E80, "type": "uint", "size": 4}, {"name": "heading", "address": 0x0580, "type": "uint", "size": 4}, {"name": "aircraftName", "address": 0x3D00, "type": "string", "size": 256} ] } request3 = { "command": 'offsets.read', "name": "myOffsets", "interval": 100 } if __name__ == "__main__": ws = websocket.WebSocketApp("ws://MYIP:PORT/fsuipc/", subprotocols=["fsuipc"], on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close) ws.run_forever(dispatcher=rel, reconnect=5) ws.send(json.dumps(request)) ws.send(json.dumps(request2)) ws.send(json.dumps(request3)) rel.signal(2, rel.abort) # Keyboard Interrupt rel.dispatch() 1
Firefly Posted October 9 Author Report Posted October 9 Hi @Paul Henty Something seems to have stopped working with FSUIPC WebSocket Server 1.1.2 (have latest FSUIPC 7.4.17 as well). With the Fenix I was previously reading Lvars successfully but now I get no responses after having declared the vars I want to monitor. I receive the response that the declare message was successfully received but I get nothing after that. Also tried the demo at http://fsuipcwebsockets.paulhenty.com/#cmdvarsread - but didn't work there either. Any chance you are able to have a look at that? Regards, Allan Jensen
John Dowson Posted October 9 Report Posted October 9 50 minutes ago, Firefly said: Something seems to have stopped working with FSUIPC WebSocket Server 1.1.2 (have latest FSUIPC 7.4.17 as well). With the Fenix I was previously reading Lvars successfully but now I get no responses after having declared the vars I want to monitor. I receive the response that the declare message was successfully received but I get nothing after that. Can you first check that you are not getting a crash in the FSUIPC WASM module - see If you list the lvars in FSUIPC (Add-ons->WASM->List Lvars) can you see the lvars you created? If not, try reloading and listing again (Add-ons->WASM->Reload & List Lvars) - does that work? This should hopefully determine if the issue is in FSUIPC or the WASM/WAPI, or an issue in Paul's WebSocketServer.
Firefly Posted October 9 Author Report Posted October 9 6 hours ago, John Dowson said: Can you first check that you are not getting a crash in the FSUIPC WASM module Looks like that was the issue. I got it working now a couple of times, even with Fenix at FlyTampa EKCH, so at least the issue seems to not be with the WebSocketServer. Thanks John.
John Dowson Posted October 9 Report Posted October 9 1 hour ago, Firefly said: Looks like that was the issue. Ok - then follow the instructions in that FAQ entry, i.e. set the WASM ini parameter LvarScanDelay to 0. Once this is set, the lvar scan will only be performed on initial aircraft load. If you create new lvars via FSUIPC with the provided lua function, or if created by writing to offsets, then FSUIPC should automatically perform a rescan/reload. However, if further lvars are created by the aircraft itself, or other add-ons, or using FSUIPC via other means (e.g. via calculator code)m then they will not be known to FSUIPC (or FSUIPC clients) until a rescan/reload is performed. I am nit sure how you (or Paul's dll) is creating lvars, but if you don't see them (after a short delay from creation, 20ms or so) then you need to explicitly ca;; for a reload - I am sure you can perform this via Paul's dll). John
harrit Posted October 17 Report Posted October 17 Hi in how far is it working now days 24 withe connection in javascript ? i have only this and never work befor white WebSocket sorry about my Englice let URI = "ws://127.0.0.1:2048/fsuipc/"; webSocket = new WebSocket(URI); console.log(webSocket.send('001')); console.log(webSocket.close(1)); webSocket.onopen = function(event) { //"ok " + console.log(event); }; //onmessage webSocket.onmessage = function(event) { //"ok " + console.log(event); }; //onerror webSocket.onerror = function(event) { //"error : " + console.log(event); }; //onclose webSocket.onclose = function(event) { //"onclose : " + var reasons = (event.reason) ? event.reason : "is closed by server!" console.log(event.type + " " + reasons); };
Firefly Posted 13 hours ago Author Report Posted 13 hours ago On 10/17/2024 at 3:38 PM, harrit said: Hi in how far is it working now days 24 withe connection in javascript ? i have only this and never work befor white WebSocket sorry about my Englice You can find complete examples in the documentation at http://fsuipcwebsockets.paulhenty.com/ - I recommend starting with those.
Firefly Posted 13 hours ago Author Report Posted 13 hours ago Hi @Paul Henty In the MobiFlight HubHop presets there are not only inputs but also outputs. Many of them are just reading lVars but some have code like this: (A:FUELSYSTEM PUMP SWITCH:2, Bool) I don't see in the FSUIPC WebSocket Server documentation any way to read this value out... Is there a way to do that? There are also some variants of lVar reading like this: (L:A380X_EFIS_L_ACTIVE_OVERLAY) 2 == ...but that's maybe just that it returns a boolean if the lVar value equals 2? Allan
John Dowson Posted 12 hours ago Report Posted 12 hours ago 54 minutes ago, Firefly said: In the MobiFlight HubHop presets there are not only inputs but also outputs. Many of them are just reading lVars but some have code like this: (A:FUELSYSTEM PUMP SWITCH:2, Bool) That is just returning the value of the simvar FUELSYSTEM PUMP SWITCH at index 2. In FSUIPC, that value can be found in offset 0x0B05, but only when you have set the ini parameter NumberOfPumps to a value > 1. In general, it will depend on the output preset definition on how you would read the value in FSUIPC (and FSUIPC clients). For simvars (or A-type variables), you can check to see if it is already in an offset and use that if so, otherwise you can add any simvar to a spare/free FSUIPC offset for both read/write. See the Advanced User guide on how to do this. 1 hour ago, Firefly said: There are also some variants of lVar reading like this: (L:A380X_EFIS_L_ACTIVE_OVERLAY) 2 == ...but that's maybe just that it returns a boolean if the lVar value equals 2? Yes, that is all that calc code does. John
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now