-
-
in libs/network/network.c, line 671
For ESP32 just got an answer from ESP_Angus here https://esp32.com/viewtopic.php?f=13&t=3941
Before doing changes in network.c, I would like to get a feedback from Gordon.
We could add an #if USE_ESP32 and have a 2nd ASSERT for ESP32 only -
On ESP32 call of socket(AF_INET,.....) returns a socket ID + an offset(named LWIP_SOCKET_OFFSET)
This results in an error message during check of socket against maxsize (32)Is there any limitation inside Espruino for socket ID, except this assert, for range of sockets ?
With other words, is this socket ID used somewhere in Espruino, for example as a pointer to an array ? -
-
@wilberforce already did
-
Gordon did some changes in Bluetooth libs to support changes for other boards.
Actual version in ESP32 branch supports this in a very early version.
To get more take a look to md files in targets/esp32/docs/bluetoothThere is also a minor change which helps for problems around jshGetTime. Hopefully this also helps for the DigitalPulse crash
Bad news: no binary available.
Espressif, ths guys behind ESP32 promised a new version before Chines next Year. And its a lot of work to get automatic generation running for new versions. I'm pretty sure @wilberforce, he is the one who knows how to do, will not waste his time for weekly changes.If you want to create your own binary, take a look to docs. There you will find a lot.
To put some water into wine, ESP-IDF is under heavy construction. Expect changes that generate some errors during compiling.Anyway, there have been some guys asking how they could help to port Bluetooth to Espruino for ESP32. Its a good time now to start ;-)
-
-
During porting jswrap_nrf_bluetooth_updateServices to ESP32, I found calls to nrf relevant functions.
ESP32 uses different walks through all of this. Most common point is use of UUIDs and handles.Searching for a better solution, found this jsvObjectGetChild(execInfo.hiddenRoot,"BLE_SVC_D",0);
Idea now is to move UUIDs and handles to this object to be more general. Value is already there.For testing of concept, this function was born. In my eyes it looks very complex.
So I've 2 questions:- whats your feedback to hold uuids and handle in BLE_SVC_D
is there a better way to read value from BLE_SVC_D ?
JsVar *jswrap_ESP32_get_Char_Value(JsVar *serviceUUID,JsVar *charUUID){ JsVar *serviceKey; JsvObjectIterator serviceIt; JsVar *serviceData; JsVar *servicesData = jsvObjectGetChild(execInfo.hiddenRoot,"BLE_SVC_D",0); JsVar *charKey; JsvObjectIterator charIt; JsVar *charData; JsVar *value; jsvObjectIteratorNew(&serviceIt,servicesData); while(jsvObjectIteratorHasValue(&serviceIt)){ serviceKey = jsvObjectIteratorGetKey(&serviceIt); if(jsvIsEqual(serviceKey,serviceUUID)){ serviceData = jsvObjectIteratorGetValue(&serviceIt); jsvObjectIteratorNew(&charIt,serviceData); while(jsvObjectIteratorHasValue(&charIt)){ charKey = jsvObjectIteratorGetKey(&charIt); if(jsvIsEqual(charKey,charUUID)){ charData = jsvObjectIteratorGetValue(&charIt); value = jsvObjectGetChild(charData,"value",0); jsvUnLock(charData); } jsvUnLock(charKey); jsvObjectIteratorNext(&charIt); } jsvObjectIteratorFree(&charIt); jsvUnLock(serviceData); } jsvUnLock(serviceKey); jsvObjectIteratorNext(&serviceIt); } jsvObjectIteratorFree(&serviceIt); jsvUnLock(servicesData); return value; }
- whats your feedback to hold uuids and handle in BLE_SVC_D
-
Sometimes, I would like to have the option using onRead. This would help to read/calculate/whatever this value, only if somebody(the client) asks for it.
Anyway, since nRF does not support this in an easy way, I'll remove it from ESP32 port.Only way to set a new value I know about is nrf.updateServices, correct ?
And the only way to read a value after being written by client is to keep track with onWrite, correct ?Description is always writable as far as I can see. Puck.js ignores writing a description. It could be done on ESP32, but I don't see a reason doing that.
I'll keep it similiar to Puck.js and last not least its less work for me ;-) -
-
Thanks for the feedback, it gave me something to think about. I'm still, and will be for next time, in the steep part of learning curve. Please see my comments.
- oh, writable is indeed an americanism, have been in the States for more than 20 times, and never heard this. Never stop learning.....
- looks like nRF does not support an read-event :-(
- take a look to https://www.bluetooth.com/specifications/assigned-numbers/format-types and https://www.bluetooth.com/specifications/assigned-numbers/units. I've no idea, how important/helpful this is, or could be. Found it by working through some sources for ESP32.
- I tried this {0xBBCC : { 0x1358 : { value : "Hello", readable : true, description:"bbcc 1358" } } } and took a closer look with nRF Connect. There is a list of descriptors with 1 entry. read this description and you will get the description "bbcc 1358". According to the arrows in nRF connect, both read and write are supported for this descriptor. I would prefer to support read only.
- For ESP32 value is stored, let me say, somewhere. Right now I use hiddenRoot for this. In READ-Event I read the value and copy/send it in a response. Therefore, it is easy to write functions to read and write the value in hiddenRoot. As far as I understand, for nRF everything is stored inside only.
- oh, writable is indeed an americanism, have been in the States for more than 20 times, and never heard this. Never stop learning.....
-
During port of Bluetooth for ESP32 some questions came up. Hopefully there is not too much "it helps if you can read" ;-)
- why do we use writable instead of writeable ? It took three coffee during test to recognize the missing e.
- the only event for a service is onWrite. Is there a reason not to use onRead ? I've added this during test for ESP32
- is there an option to define type of value for "mySpecialService" ? This can be done with a descriptor, but how would I define in javascript ? NRF connect supports byte, uint, text and some others.
- how would I define writeable for value only, and not for description ?
- how would I read or write value of a characteristic?
- why do we use writable instead of writeable ? It took three coffee during test to recognize the missing e.
-
-
I've a memory leak (JsVars) in my bluetooth implementation.
For easy testing I built a simple testfunction.
After each call of this function, process.memory.free is reduced by 2
Whats wrong in my code./*JSON{ "type" : "staticmethode", "class" : "ESP32", "name" : "test", "generate" : "jswrap_ESP32_test", "params":[ ["text","JsVar","test text"] ] } for testing only */ JsVar *tmp; void jswrap_ESP32_test(JsVar *text){ char txt[20]; jsvGetString(text,txt,sizeof(txt)); // this is a short replacment of the data I get in Bluetooth tmp = jsvNewStringOfLength(sizeof(txt), txt); return; }
Tried to add jsvUnLock and/or jsvUnRef on tmp, and sooner or later got HALT
-
Thanks for the feedback, each information is its own step for my (hopefully better) understanding.
There is a function deep inside Bluetooth stack sources, which might help.
For now I bypass the data from jswrap_nrf_bluetooth_getAdvertisingData and use the API-Call which takes a structure to set ADV data.
At least for first examples it works.
Next step will be how to handle readable and writeable for char and descriptors -
After digging through ADV-functions for esp32 I found these only :
- esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data) //adv data is something like ble_advdata_t
- esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len)
As expected esp_ble_adv_data_t is different to ble_advdata_t. There is some overlapping and I'm sure to find a way to get it working
But I cannot find anything like adv_data_encode. Looks like it happens behind the curtain.
In my (poor) understanding of jswrap_nrf_bluetooth_setAdvertising the only way to make this matching would be a big rebuild of jswrap_nrf_bluetooth_setAdvertising.
Any better idea ? - esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data) //adv data is something like ble_advdata_t
-
Working on NRF.setAdvertizing there are some FIXME on the road (jswrap_bluetooth.c)
Actually I reach these:- sd_ble_gap_device_name_set
- sd_ble_gap_adv_data_set
- adv_data_encode
For the first one, there is an idea what to do.
The others are some more questionmarks on a long long way.
Generally, I would prefer not to have device related code seperated by #if in a core file
@gordon, whats your point to that, could we move them to bluetooth.c ? - sd_ble_gap_device_name_set
-
Well, the only thing I know is, in a sample there is this:
- - Descriptor: Characteristic User Description
- - Descriptor: Client Characteristic Configuration
- - Descriptor: Characteristic Presentation Format
Found some more information in O'REILLY Getting started with Bluetooth Low Energy.
To be honest, no. of questionmarks in my face is more than before.
I'll try to ignore them for now :-)
- - Descriptor: Characteristic User Description
-
Thanks to Gordon, I now have a puck for testing.
It took some time to figure out, how to connect WebIDE from windows 10 puck.
Chrome or webpage did not work, but installation of local WebIDE application made itAt the end this is my way today:
- open settings for Bluetooth
- click add bluetooth device
- wait for my puck to appear and the click
- wait for ready, and close window
- puck should now appear in bluetooth devices
- now start local WebIDE (nw.exe)
- click connect
- select puck in list and it should work now.
After switching off power from puck, all steps need to be done again.
Next step was to setup puck as server
function set(nr){ var ble; switch(nr){ case 1: ble = {0xBCDE : { 0xABCD : { value : "Hello", readable : true } }, 0xCDEF : { 0xBCDE : { value : "Hallo", readable : true }, 0x1234 : { value : "Egon", readable : true } } }; break; case 2: ble = {0xBCDE : { 0xABCD :{ value : "hello", readable : true } } }; break; } NRF.setServices(ble,{}); NRF.setAdvertising({}, {name: "MyPuck",showName: true,discoverable: true}); }
After starting this, I switched to my mobile phone and started nRF connect, but puck was not found.
Puck appeared on my mobile only after disconnecting puck from WebIDE.
Is there a way to have puck connected to WebIDE and see it in my mobile ?
Otherwise testing would be difficult. - open settings for Bluetooth
-
Bluetooth supports descriptors for characteristics.
In bluetooth.c for nrf is this:char_md.p_char_pf = NULL; char_md.p_user_desc_md = NULL; char_md.p_cccd_md = NULL; char_md.p_sccd_md = NULL;
I can't find a way where they are used.
Can descriptors be defined in javascript ?
If yes,is this the right place to search for descriptors ? -
To get Espruino(ESP32) compiled with USE_BLUETOOTH=1 changed this
added includes to bluetooth.h
#include "jsutils.h"
#include "jsvar.h"added variables in bluetooth.c, I'm pretty sure there's a better way, but to avoid side conflicts, ...
volatile BLEStatus bleStatus;
uint16_t bleAdvertisingInterval;
volatile uint16_t m_conn_handle; -
-
During testing Bluetooth, connection to more than one board is helpful.
Doing this with WebIDE and putty is doable, but comfort of WebIDE is missing in one window.
Gordon guided me to http://www.espruino.com/Web+IDE#as-a-native-application.
This works fine, but only with one session.At the end I found sandboxie, an application which starts applications in a sandbox.
In a first test I run 2 WebIDE's and connected to two boards.
For more than 1 sandbox you need to buy a licence.
Is there anybody having more experience with this tool ? -
Some time ago, I created some tutorials http://jumspruino.jumware.com/docu/Extensions/
Only a few guys will still know where they are.
Would it be an option to add them to EspruinoDocs ?
@wilberforce,
could you please create a list of all changes to sdkconfig, you did for ESP32 ?
It would help to stay on same track as you are during implementation of bluetooth
I would then add this to ESP32-docu on github
@gordon, wilberforce, removed the assert for testing. At least Espruino now starts without problems and BLE is running. Some more testing needs to be done, but there is light ....