Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] add net and event modules #44

Open
radiocom opened this issue Oct 21, 2022 · 2 comments
Open

[feature request] add net and event modules #44

radiocom opened this issue Oct 21, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@radiocom
Copy link

I don't know how many native functions I need to add in order to connect to some TCP ports.
we need some demos like the ffi module, thanks.

@coder-mike
Copy link
Owner

we need some demos like the ffi module, thanks.

Are you referring to this FFI module?

I don't know how many native functions I need to add in order to connect to some TCP ports.

You would likely want to find a C or C++ library that handles networking. If you don't already have one in your firmware, I can recommend trying Mongoose. You can then integrate with the Mongoose API using something like the Microvium FFI example library.

Depending on your level of experience, you could wrap Mongoose into a Microvium library for others to use as well. Similar to how the Microvium FFI example library is able to produce C++ code at compile time and then link to it at runtime, a Mongoose wrapper library can "generate" the Mongoose C++ code (i.e. just fs.writeFileSync to dump the Mongoose files to disk) as well as all the JavaScript-to-C++ bindings. I'll probably do this at some point if nobody else does, but since it doesn't require any additional engine capabilities, it's a library that in theory anyone can write (and I'm happy to advise and help with the design).

Having said that, even if you just do basic integration for your own project, I'm happy to help. Just let me know where you get stuck.

@davidchisnall
Copy link
Contributor

@radiocom, it's not really clear what the right abstraction is for your use case, without knowing what it is. Generally, anything that has raw access to TCP sockets needs to do buffering of messages and parsing. This is likely to stress the Microvium heap quite a bit. Exposing higher-level network protocols requires a lot less work in the JavaScript, but more on the integration side. For example, something like MQTT might be exposed as a simple callback for handling an event and a function for publishing to a specific node, so a small amount of JavaScript on the device can drive a lot of policy and not require you to reimplement an efficient C/C++ MQTT client library in interpreted JavaScript.

@coder-mike coder-mike added the enhancement New feature or request label Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants