[ST Edge] - Local HTTP Requests

Thanks for the insight. Yet another example how powerful and complex these drivers can be. My coding skills are zero so I just need to wait what you guys come up with.

1 Like

Fun fact, having multiple ā€œdevicesā€ on a single raspberry pi was my original reason for starting thinking about the project that eventually became Edge Drivers. DTHs were so inextricable tied to MAC addresses that it basically would have never been possible to make them work this way.

3 Likes

I was thinking of a solution to this the other day. Can you configure your device to communicate over multicast address? If so, then you could kind of hack things and have your driver monitor the multicast and look for a ā€˜signatureā€™ in your deviceā€™s transmission to pick out its messages. Definitely unconventional and wouldnā€™t follow any protocol standards but it might work. I may try this approach for a Shelby motion detector I have that can send messages to a configured ip:port when motion is detected.

Yes! I absolutely do this; I have a RPI running all sorts of ā€˜devicesā€™ that Iā€™m in the process of converting over to Edge driver(s).

I think that the SSDP - NOFITY will be useful in this case, i.e. the driver would be broadcasting its luxureā€™s server IP and port.

This implementation would imply one additional step into the flow (driverā€™s IP/PORT acknowledgement) but, will guarantee M2M communication.

@erickv

In looking at the example LAN drivers I could find (all the way back to alpha code), Iā€™ve seen a few different approaches with HTTP-related networking. Can you comment on these and is there one thatā€™s most recommended?

http = require "socket.http"
http = cosock.asyncify "socket.http"
http = require "luxure"

The first is what you recommended in the beginning of this topic.
The second is from older examples and I have used per earlier guidance from Patrick
The third I know is a third-party HTTP module, but is socket.http preferred over this?

Iā€™m rather desperate to find ways to reduce or eliminate the known platform socket errors, as I get them nearly all the time now - especially whenever I try to update a driver that is using HTTP calls.

And related to using something like luxure, how do we even know what Lua library options are available (in general) to us in the Edge environment? Is there a list somewhere?

Hey, @TAustin

The difference between using the socket module from beneath cosock or from direct import is that the cosock implementation allows you to perform non-blocking socket operations.

And the luxure library, as its readme refers, is intended to build HTTP/TCP Servers, which is preferred over raw socket.tcp servers because the library does the library already parses the HTTP strings into tables and allows you to enable custom middlewares in a express-like structure.


You can check the loaded libraries and modules looping the package.loaded module.

1 Like

Not sure this will really do what I was asking: I was wanting to get a list of ALL libraries available in the Edge environment, not a list of the ones my driver has loaded. For example, luxure doesnā€™t get listed unless I have it requireā€™d in my driver.

I believe that right now it isnā€™t possible, however, Iā€™ll comment it out with our engineers to check if it is possible to include at least a documented reference of the libraries available.

2 Likes

Documentation is good :slightly_smiling_face:

2 Likes