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 send requests to JSON-RPC with curl?

kiotekiote Estonia
edited March 21 in Mongoose OS

Hi! I'm using latest mongoos os + ESP 32 for simple sensors' reading.
Would like to expose this data to other services in local network and JSON-RPC seems to be a good way to do that.
Have to say I have no previous experience with embedded programming but have some in general API-programming (both using and making).

so I've added a simple function to my main.js:

RPC.addHandler('TempHumid.Read', function(args) {
  return { temp: dht.getTemp(), humid: dht.getHumidity() };
});

and I know the device's IP address.

but when I'm trying to curl there, for example like that:

➜  ~ curl -o - 192.168.2.79/rpc/TempHumid.read
curl: (7) Failed to connect to 192.168.2.79 port 80: Connection refused
➜  ~ curl -d '{}' -o - 192.168.2.79/rpc/TempHumid.read
curl: (7) Failed to connect to 192.168.2.79 port 80: Connection refused

I'm getting "Connection refused" errors, looks like I'm doing something wrong, or something is missing

Can someone advice, please?

Comments

  • nliviunliviu Romania

    main.js or init.js?
    RPC - Remote Procedure Calls

    Is TempHumid.Read listed by mos call RPC.List?

  • kiotekiote Estonia
    $ mos call RPC.list
    [
      "TempHumid.Read",
      "Dev.Remove",
      "Dev.Erase",
      "Dev.Write",
      "Dev.Read",
    ...
    ]
    

    and it's init.js, instead of main.js I have main.c

  • kiotekiote Estonia

    ah! so I ended up adding these two lines to mos.yml:

      - origin: https://github.com/mongoose-os-libs/http-server
      - origin: https://github.com/mongoose-os-libs/rpc-common
    

    and now it's working as expected. Well, I was simply lacking http server :smiley:

Sign In or Register to comment.