thanks @Gordon I have no experience with that. Do you think its possible to make it work with bangle watch? There is a joystick app for bangle.
You mean a Bangle.js watch controlling your car? Absolutely - I don't think you need to use HID for that.
As an example, there's the Smartibot app - that communicates with a Smartibot (which also runs Espruino): https://github.com/espruino/BangleApps/blob/master/apps/smartibot/app.js
But basically all it does is:
Thanks @Gordon I will use that as an example. That will be nice option for controlling it. I didnt know about that project and its using espruino! Its cool, might be a nice Christmas gift for my toddler. They also have a web app controller so it might be a good starting point.
I think I have my three options: phone webapp, Bangle watch and IDE testing plugin.
BTW quick google search and I found this: https://www.instructables.com/ESP32-Bluetooth-BLE-Remote-Control/
I think it should work for me as well. I have something similar. I made a post about in the past.
Probably the best and default option should be just using a phone with a webapp anyway.
That's good - so it should be possible. To be honest 90% of the code in that instructable seems to be handling scanning for services and things - which Espruino handles for you anyway - so doing similar in Espruino should be pretty easy.
I just wish I had one here to try out :)
I spend some time over Christmas break on the web joystick for the BolidJS. I feel like it should be separate project that could be used for other RC things. That might be idea for future or a fork of a current joystick. Anyway the code is here: repo WebJoystick and can be tested here: test WebJoystick
Right now its very prototype like with lots of debug features.
Main things to address:
The code needs some refactoring as well :) I feel like the tiny dash controls will have to be replaced with something that scales. Any suggestions for a library with gauges and graphs are welcome.
I am wondering what is the best approach for updating a motor PWM over web bluetooth from the joystick or other device. In the past pre-espruino implementations I would just send data frame and commands would be just fired periodically (or on event) on the control board. With espruino you can send a whole command over BLE like:
I have a feeling if I do that with too hight update rate by moving a knob in my web joystick that would cause problems. It would be fine for toggling lights but not for continuously updated value. Do I just have to setInterval on the controller side or I could listen for an event from BLE? I think listening for an event would be best. Maybe with some mechanism for discarding uncaught events so they dont queue. Is there a best practice here?
If you can connect to a different characteristic, and send the "commands" there, I think you should define a custom characteristic for controlling the car. NRF.setServices, and handle the onWrite event.
I imagine pretty similar to what you did previously.
And since payload for one command would be less than the packet size, the whole command arrives as one unit, command handling would be extremely simple, no need for buffering or anything like that. And not "polluting" the Nordic Uart with car control commands.
I assume you pair - you have a connection - where you exchange data. So you would be able to even have handshake - ack / nack - to make sure your commands get thru.
On the sending side you can poll your controls and if do not notice any change (or change within boundaries) you do not send the information. When you send the information, you want to get it acknowledged - ack received for that command. If nack or any tampering has happened, you resend / retry. In addition to that you may also implement a heart bead. If your bolidJS does not get the beat anymore, it just stops. Ao you can make controler side a queue for outgoing commands. Feeding the queue you use the ui and handle it the same way: poll continuously and for each change you put a command into the buffer and trigger the working of the buffer. Just make sure you start every cycle with a setTimeout(... to break the JS execution streak (not hogging the only cpu you have). - Just some thoughts.
@AkosLukacs Thanks, using onWrite in NRF.setServices seems to be what I was looking for. I am thinking about around 100ms update rate when the knobs for acceleration and steering are operated from joystick. Thats what I set the interval to on the webjoystick side. Like you say there is no big data payload. From what you are saying I dont need buffering. I can deal with it later once I test the setServices.
I guess I cant use the uart.js with default settings or at all on the web bluetooth side? Would be nice to see some example if you came across anything similar.
@allObjects the heart beat is a good idea. I dont want the car to drive into walls full speed once it loses communication. That can be implemented easily. I will look into the Acknowledge on a later stage once I have basics working. Should be good idea for reliability.
something like this: https://play.google.com/store/apps/details?id=iyok.com.blejoystick&hl=en_US&gl=US
or for apple fan
There is few joystick apps around. I looked through them but usually they are rather simple button type, limited control. I am aiming at something with more accuracy. Here is my prototype (my web development skills are very limited and its a work in progress):
Also I dont want to go HID way straight away. I will follow @AkosLukacs suggestion and handle onwrite event after setting up NRF.setServices with custom data frame.
Right now I am trying to figure out if on WebBluetooth side I can stil use puck.js/uart.js or I need to go to lower level.
For a proportional joystick I used code derived from this https://create.arduino.cc/projecthub/iot_lover/arduino-web-based-joystick-02ca54
But your WebJoystick prototype looks cool so perhaps treat ^^^ just as an inspiration.
Thanks @opichals that looks cool and I didnt come across it. Right now I am focusing on bluetooth connection. Yesterday I had some luck making it work from both sides using custom services. A lot to learn.
Once I have the whole system going I will have to refactor a lot of things so keep the inspirations coming :) Scalable js buttons and gauges would be something I will be looking for.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem