Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

RPC.addHandler

I added the following code from the example to my init.js

RPC.addHandler('Example.Increment', function(args) {
    print(args);
    if (args !== undefined && args.num !== undefined) {
        return { num: args.num + 1 };
    } else {
        return { error: 'num is required' };
    }
}, null);

My ESP8266 is connected to iot.eclipse.org and I can send messages from my ESP and this works perfect. (I use hivemq)

When I send a message to my RPC channel (esp8266_XXXXXXX/rpc/Example.Increment, message: aaa, or {"a":2}
I get the following output in console. The message is not arriving ?

null 
[Jun 24 15:38:23.402]   at init.js:25
[Jun 24 15:38:23.402]   at api_rpc.js:35
[Jun 24 15:38:23.406] MJS callback error: type error

What is my mistake ?
Holger

Comments

  • SergeySergey Dublin, Ireland
    edited June 24

    The answer to your question is the same as answer to this question:
    what is a valid JSON value Example.Increment expects as an input ?

    If you're crafting RPC messages manually, please read https://mongoose-os.com/docs/libraries/core/rpc.html

  • CapsicumCapsicum Germany
    edited June 28

    With the help from this post:
    https://forum.mongoose-os.com/discussion/comment/3612/#Comment_3612

    I sent the message through "HIVEMQ"

    It works now. I get a result and additional an error:
    esp8266_DXXXXX 30 1498684251.046 2|mg_rpc_get_channel_i Unsupported connection scheme in in the Log Channel

    How to solve this ?

  • rojerrojer Dublin, Ireland

    can you show example of the request you're sending? looks like it interprets its source as URL.

  • rojerrojer Dublin, Ireland

    better yet, set debug.level=3 and post the whole exchange.

  • CapsicumCapsicum Germany

    Input:
    {"src":"out-topic","id":1,"method":"Sum","args":{"a":1,"b":4}}

    Output:

    [Jun 29 21:27:34.944] mgos_mqtt_ev         MQTT event: 203
    [Jun 29 21:27:34.951] mg_rpc_ev_handler    0x3fff107c GOT FRAME (62): {"src":"out-topic","id":1,"method":"Sum","args":{"a":1,"b":4}}
    [Jun 29 21:27:34.964] mg_rpc_parse_frame   1 'out-topic' '' 'Sum'
    [Jun 29 21:27:34.979] mg_rpc_channel_mqtt_ Published [{"id":1,"src":"esp8266_D50D1B","dst":"out-topic","result":5}] to topic [out-topic/rpc]
    [Jun 29 21:27:34.991] mg_rpc_send_frame    0x3fff107c SEND FRAME (60): {"id":1,"src":"esp8266_D50D1B","dst":"out-topic","result":5} -> 1
    [Jun 29 21:27:35.007] mg_rpc_ev_handler    0x3fff107c FRAME SENT (1)
    [Jun 29 21:27:35.013] mg_rpc_get_channel_i Unsupported connection scheme in 
    [Jun 29 21:27:35.017] mg_rpc_get_channel_i '' -> 0x0
    [Jun 29 21:27:35.149] mgos_mqtt_ev         MQTT event: 204

    Result:
    {"id":1,"src":"esp8266_D50D1B","dst":"out-topic","result":5}
  • rojerrojer Dublin, Ireland

    hm, that's strange. thanks, i'll take a look!

  • mtraxmtrax Canberra

    @rojer did you understand why this is happening.. I'm seeing the same error

    sending msg via my local mqtt server.

Sign In or Register to comment.