RPC over HTTP does not work

#1
  1. My goal is: Call remote Json-RPC server
    hardware: ESP32-PICO-KIT
    mos version: 20190522-131204/2.14.0-g71e2991

  2. My actions are:
    RPC.call(“http://192.168.2.16/test.php”, ‘Config.Save’, {a: 1, b: 2}, function (resp, ud) {
    print(‘Response:’, JSON.stringify(resp));
    }, null);
    library list:

  1. The result I see is:
    [Jun 29 21:41:34.986] mg_rpc.c:225 Unsupported connection scheme in http://192.168.2.16/test.php

  2. My expectation & question is: Is it possible to use HTTP transport to make outgoing RPC call? My second question is: I have found a lot of links with examples, which used HTTP object from api_http.js But I have not found this library. So, is it possible to make POST/GET query from mjs?

#2

192.168.2.16 is a mOS device?

#3

no, it is workstation with nginx/php server

#4

api_http.js is part of the mjs library.

1 Like
#5

It looks like http outbound requests are not supported. Only ws/wss.

#6

My goal is: Call remote Json-RPC server
hardware: ESP12 NodeMCU


My actions are

I writing in C…
When I call in mos GUI mos call Sum '{"a":1, "b": 2}' it works.
But when I try to call trough Imsomnia it doesn’t work.
I try the endpoints: http:DNSAddress/rpc and http:IPAddress/rpc
And the payloads: { "id": 1932, "method": "Sum", "params": {"a": 2, "b": 1} } and {"a":1, "b": 2}

The result I see is
The DNSAddress is recognized, but the rpc endpoint doesn’t

My question is:
What am I doing wrong?


My mos.yml:

libs:
  - origin: https://github.com/mongoose-os-libs/boards
  - origin: https://github.com/mongoose-os-libs/ca-bundle
  - origin: https://github.com/mongoose-os-libs/rpc-service-config
  - origin: https://github.com/mongoose-os-libs/rpc-service-fs
  - origin: https://github.com/mongoose-os-libs/rpc-uart
  - origin: https://github.com/mongoose-os-libs/si7021-i2c
  - origin: https://github.com/mongoose-os-libs/rpc-common
  - origin: https://github.com/mongoose-os-libs/http-server

my init on main.c:

{
  mg_rpc_add_handler(mgos_rpc_get_global(), "Sum", "{a: %lf, b: %lf}", sum_cb, NULL);
  return MGOS_APP_INIT_SUCCESS;
}
#7

Hey people,

I repeated after some sleep and it worked :sweat_smile:
I used the url http://10.0.0.105/rpc with the body as { "id": 1932, "method": "Sum", "params": {"a": 2, "b": 1} }
The return was { "id": 1932, "src": "esp8266_0270A2", "result": 3.00 }

I also tested the url http://10.0.0.105/rpc/sum with the body as {"a": 2, "b": 1}
The return was 3.00
=> this worked because the result was a single float value

The 10.0.0.105 is the IpAddress, not the DNSAddress

My problem was that I used HTTPS, and should have used HTTP
Thanks guys, it worked :partying_face: