Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

How to do RPC call through persistent websocket?

MisterAMisterA Belgium
edited October 2017 in Mongoose OS

Hi,

I have a proof of concept setup with three ESP32's.
The first ESP32 is the master and has secure websocket's enabled. IP: 192.168.1.200
The second ESP32 is slave 1 and has the master as it's default secure websocket connection. IP: 192.168.1.201
The third ESP32 is slave 2 and has the master as it's default secure websocket connection. IP: 192.168.1.202
The idea is to have more slaves connecting to the master in the future. And have all slaves communicating securely with each other through the master.

When I bring up all three devices, on the master I see in the logs:
[Oct 31 23:33:47.194] mgos_http_ev 0x3ffe2578 HTTP connection from 192.168.1.202:62922
[Oct 31 23:33:48.147] mgos_http_ev 0x3fff1580 HTTP connection from 192.168.1.201:54993

So the persistent connections are working I believe. On the slaves I see 'WS Handshake done'.
On slave 1 I have this button handler. (The rpc call target is left empy since it uses the default persistent connection to the master)

GPIO.set_mode(0, GPIO.MODE_INPUT);
GPIO.set_button_handler(0, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 100, function(x) {
  print('Button press, pin: ', x);
 RPC.call('', 'Light', {lp: 2}, function (resp, ud) {
  print('Response:', JSON.stringify(resp));}, null);
}, null);

On the master I have a RPC handler:

        RPC.addHandler('Light',function(args){
          RPC.call('wss://192.168.1.202/rpc', 'GPIO.Toggle', {pin: args.lp}, function (resp, ud) {
          print('Response:', JSON.stringify(resp));}, null);
          return true;}) 

So the master tries to do a RPC call through the persistent connection it has with slave 2, and this is the part that fails. In the logs on the master I see this:

[Oct 31 23:47:54.924] mg_rpc_channel_ws_ou 0x3ffd9dbc Connecting to wss://192.168.1.202/rpc, SSL? 0
[Oct 31 23:47:56.941] mg_rpc_channel_ws_ou 0x3ffd9dbc Connecting to wss://192.168.1.202/rpc, SSL? 0
[Oct 31 23:48:00.957] mg_rpc_channel_ws_ou 0x3ffd9dbc Connecting to wss://192.168.1.202/rpc, SSL? 0
[Oct 31 23:48:08.983] mg_rpc_channel_ws_ou 0x3ffd9dbc Connecting to wss://192.168.1.202/rpc, SSL? 0
[Oct 31 23:48:24.981] mg_rpc_channel_ws_ou 0x3ffd9dbc Connecting to wss://192.168.1.202/rpc, SSL? 0

On Slave 2 I can't see anything in the logs.

At first I thought I got it working by changing:
wss://192.168.1.202/rpc
into
ws://192.168.1.202/rpc

And it seemed to work, but then I realized the call was not going through the secure channel, but instead a not secured call was done to slave 2.

How can I do the RPC call from the master through the secure persistent connection towards slave2?

Sign In or Register to comment.