How is Snap4Arduino implemented?

Since below factors:

  1. firmata protocol is used
  2. https/http server is used for outside world(boards)
  3. snap! image is NOT modified for Snap4Arduino??? right?

How Snap4Arduino is implemented?
a) Which code is used for firmata --> https/http bridge?
b) How [Arduino] category is established in Snap4Arduino IDE?
c) Where is [Arduino] category's block codes?

@daniel2008_12
Github link is: GitHub - bromagosa/Snap4Arduino: Binding Snap! and Arduino together

For other than 8bit processors (Arduino family), also take look at MicroBlocks for physical and real-time computing needs.
MicroBlocks is fully integratable with SNAP and will offer you much more flexibility than working under the Firmata model.
For examples of SNAP interaction with MB, check out: Interacting with Snap! | MicroBlocks Wiki
Enjoy.

Hi, Daniel.

We're not using any bridges. This project uses nw.js, which lets us mix Node.js and Webkit. That means we can call OS-level JS from the "browser" side.

You'll find what you're looking for here: Snap4Arduino/arduino.js at a4c0b1775444b4bdbbc296f6fccc6d7f9517a397 · bromagosa/Snap4Arduino · GitHub

Here's the relevant code: Snap4Arduino/objects.js at master · bromagosa/Snap4Arduino · GitHub

And here's the relevant code: Snap4Arduino/threads.js at master · bromagosa/Snap4Arduino · GitHub

And I second Turgut's suggestion to take a look at MicroBlocks for 32 bit processors :slight_smile:

@tguneysu @bromagosa Thanks for the reply, I'm sure that I need some time to understand much more.

And at the mean time, I think my intention (to ask much detailed dev info) is that we are tring to control iNav/BetaFlight flight controllers through MSP protocol, which is binary serial(UART) frame format.

And I also think use Snap4Arduino's framework might be take me less time to complete the task. What do you think? If Snap4Arduino can do the work, what steps should I take?

--
The outcome should be something much more like Snap4Arduino:
e.g.
a) Connect/disconnect Arduino ==> Connect/disconnect AutoPilot
b) Set pin to value ==> set throttle/pitch/roll/yaw to value

Do you want to:

  • create the PC application acting as a "Configurator/Ground Station" part of the MSP and already have communication hardware accessible to computer via USB?
  • or wish to construct a device capable of exchanging MSP packets with FC via any means (WiFi, BLE, ESP-Now, RF, LoRa, UART wired) and PC at the other side via USB?

:snap: has a built-in "Serial Ports" library that can be used with USB-CDC or Classic Bluetooth SPP devices.

@dardoro Currently, community has configurators connectting FC with USB-CDC or Bluetooth SPP.

What I'm trying to do is connectting FC via wifi first. Maybe we can call it a device, as data flows

a) FC<-->wifi device (embedded https/http server) <--> SnapLibrary <--> Snap IDE (Snap4Arduino or snapWeb)
b) FC<-->wifi device (TCP/IP server) <--> PC/laptop https/http server <--> SnapLibrary< --> Snap IDE (Snap4Arduino or snapWeb)

So where should i start, any suggestion and ideas?

Note: wifi device might be limited capabilities, just used as a communication channel.

Do You think of a PC connected to a remote wifi device?
To make it more verbose
PC{Snap, std WiFi( client)} <-------- HTTP -------->Drone{WiFi device(AP, https server) FC}

And you want to build a PC application and a WiFi device?

Yes,current plan is.

Do you have any suggestions?

PC --- wifi network --- drones ==> then multi drone

For multi drone scenario more suitable will be
PC{ WiFi SoftAp} <------>Drone{ Wifi device( client)}
Or even extra Wifi device acting as an AP for the whole "family", connected to PC as an USB device.
Some vendors offers a proprietary RF or WiFi extensions to act as a connection-less and/or long range "mesh" or "cloud" (ESP now , NRF).

When a PC and a drone connect to the same WLAN, you can use the standard :snap: URL block to send a MSP packet to the drone and receive a response. But you know that already :slight_smile:

If FC understand only raw TCP socket, some form of the HTTP/TCP gateway is needed (Python,C).
Or you can bundle :snap: as an Electron.js application and use native TCP socket library.

Well, it's really close to my objective.

One last question about dev stuff: How to bundle snap & https/http service, is there any script (Hmmm.. something like linux shell scritps.) that combines https/http server and snap, and how to do this?

There are no such scripts, but Snap4Arduino Desktop is one such bundle, and it includes an HTTP server, which is described at https://snap4arduino.rocks/ => HTTP PROTOCOL

If you try to use, as a wifi device, Esp8266 in AT mode a kind of http<==>tcp gateway is required (e.g. GitHub - reddec/http2tcp: Expose your TCP application to WEB)

or you can modify S4A and add TCP client blocks.

Thanks for you time and patience. I'm NOT familiar with js and snap4arduino dev, just basic knowledge about C/C++ in embedded dev. So how snap4arduino is launched or started, something like PX4 boot sequence (initialization).

Currently, I have had a glimp of js programming (node blabla.js, like gcc helloworld.c ==> a.out, run ./a.out).
Is there any simple code framework for snap + https/https(js) , very basic /easy code example simillar to snap4arduino .

Or any guide link for me to add code for snap4arduino, such as (USB CDC, Bluetooth SPP)Arduino Component, we call it (WiFi) MSP Component.

I'm not aware of any public low level documentation other than the source code from repo :wink:

I will check if the S4A's "Network serial port" can be abused as a raw TCP connection.

:rofl: Yeah! I hope some with low level coding skill can help me out if there is NO documents.

And thanks for your time. :grinning: