-
My goal is: [ read-write some parameters using GET POST request using mJS (now not C )]
-
My actions are: [ mos.yml has https://github.com/mongoose-os-libs/http-server ]
It can answerded with html file, but how to run any changes? For example - I have sensor on ADC pin, how to show value in html page? -
The result I see is: [ demo with index.html works ok. But if i modify page and insert and try to load(‘api_adc.js’); for read sesor - i catch error in browser’s console. ]
-
My expectation & question is: [ If it is not possible with http_server, it can be implemented with api_net.js but need lot of code. Can I do something on a “server side” with RPC WebSocket? How to do it? Little example will be enought for start. ]
Add a rpc function in mJS to read the ADC and make a rpc call from the html file.
How to call RPC from HTML? I have no idea.
There is function
static void mgos_http_ev(struct mg_connection *c, int ev, void *p, void *user_data)
in a file mgos_http_server.c
Can it used in mJS ?
Thank you. I was afraid using axios, but when you link it me I see - axios is optional, the main is
axios.post(‘/rpc/Config.Set’
address and type of request.
( C code in a big new project make headache me. And I dont know how to get source for view some detail.)
RPC.addHandler(‘Temp.Read’, function(args) {
return { value: ADC.read(0) };
});