-
-
Ok, it's working - thank you!
but now I see another problem ,
when I try to read the pin status using this command:NRF.setServices({ "3e440001-f5bb-357d-719d-179272e4d4d9": { "3e440002-f5bb-357d-719d-179272e4d4d9": { description: "Setup Led", // optional, default is null, writable : true, readable : true, notify: true, maxLen : 10, value : "Setup_Data", onWrite : function(evt) { data = evt.data[0]; g.clear(); g.setFontVector (20); g.drawString('Data receive',2,2); g.drawString(data,2,40); g.flip(); if (data =="1") { // if (data < 18) { digitalWrite(LED, 1); digitalWrite(Relay_Pin, 1); } else { digitalWrite(LED, 0); digitalWrite(Relay_Pin, 0);} Relay_Status = digitalRead(Relay_Pin); } }, "3e440008-f5bb-357d-719d-179272e4d4d9": { description: "Device Temp", // optional, default is null, readable : true, notify: true, value : [E.getTemperature()] } } }, {});
it turn off the led that connected to Relay_Pin
when I remove the this line - the led stay on
what could be the problem ?
when I read the data from "nRF" I can see the value is "0x01"and one final "understanding" question:
if I understand correct - there is no need for the connected device to know the Service UUID , just the CHAR uuid
there is no used of the service - right ?***I mange to make my Python code work - and there I only used the CHAR UUID , didn't use \ took any attention for the Service UUID
-
when I print to the OLED
E.getTemperature() - I get 24.5 , so it's OK
so if I will use this Characteristic for the temperature '2A6E' - will it show me ok on the nRF?
I have looked here
https://programmaticponderings.com/2020/08/04/getting-started-with-bluetooth-low-energy-ble-and-generic-attribute-profile-gatt-specification-for-iot/and you can see in the nRf he is showing decimal value and say it's temp
https://programmaticponderings.files.wordpress.com/2020/08/screenshot_20200731-185558-5.pngI guess I will need to change the UUID also , no ?
Thanks ,
About my code
- can I see the MAC of the remote device that connected?
I want to print it on the OLED , for testing I have wrote this code , it's seem to be working,
my problem is when I disconnect:
LED2 is off (as it should be)
but on the OLED I still see "Connected" and the temp is changing every 5 seconds
I guess it's because the Interval function that is still running
can you see what I did wrong?My_MAC = NRF.getAddress(); Relay_Pin = 22; print("My MAC address is " , My_MAC); var n = 0; function start(){ // write some text g.setFontVector (20); g.drawString("David Test!",2,2); g.drawString("BLE ON",2,40); // write to the screen g.flip(); } function BLE_Connect(){ setInterval(function() { NRF.updateServices({ "3e440001-f5bb-357d-719d-179272e4d4d9" : { "3e440008-f5bb-357d-719d-179272e4d4d9" : { value : [E.getTemperature()],//to be able to see that read is correct notify: true } } }); g.clear(); g.setFontVector (20); g.drawString("Connected!",2,2); g.setFontVector (10); g.drawString("Temp is: " + E.getTemperature(), 1, 40); g.flip(); }, 5000); } function BLE_Disconnect(){ g.clear(); g.setFontVector (20); g.drawString("Waiting!",2,2); g.flip(); } var i2c = new I2C(); i2c.setup({ scl : D20, sda: D19 }); var g = require("SSD1306").connect(i2c, start); NRF.setAdvertising({}, {name:"OfficeTest"}); NRF.setServices({ "3e440001-f5bb-357d-719d-179272e4d4d9": { "3e440002-f5bb-357d-719d-179272e4d4d9": { description: "Setup Led", // optional, default is null, writable : true, readable : true, notify: true, maxLen : 10, value : "Setup_Data", onWrite : function(evt) { data = evt.data[0]; if (data < 18) { digitalWrite(LED, 1); digitalWrite(Relay_Pin, 1); } else { digitalWrite(LED, 0); digitalWrite(Relay_Pin, 0);} } }, "3e440008-f5bb-357d-719d-179272e4d4d9": { description: "Device Temp", // optional, default is null, readable : true, notify: true, value : ["Temp_Location"] } } }, {}); setInterval(function() { NRF.updateServices({ "3e440001-f5bb-357d-719d-179272e4d4d9" : { "3e440002-f5bb-357d-719d-179272e4d4d9" : { value : [data, heartrate],//to be able to see that read is correct notify: true }, } }); }, 5000); // On disconnect, turn off led NRF.on('disconnect', function() { digitalWrite(LED2, 0); BLE_Disconnect(); }); NRF.on('connect', function() { digitalWrite(LED2, 1); BLE_Connect(); });
Thank you again ,
- can I see the MAC of the remote device that connected?
-
-
-
I'm using this device
128×64 OLED display module (SSD1306) , I will tryjust to be ready
if I take the code:function start(){ // write some text g.drawString("Hello World!",2,2); // write to the screen g.flip(); } // I2C I2C1.setup({scl:B6,sda:B7}); var g = require("SSD1306").connect(I2C1, start);
it's should work ?
will change it to print if someone is connected or notThanks ,
-
so 3.5 questions about it :
- I guess I need to convert the 0x1D to 29 using some java hex to DEC function ?
- I'm trying to read it using nRF , as I understand from the API Reference
> NRF.setServices({ 0xBCDE : {
> 0xABCD : {
> value : "Hello", // optional
> description: "My Characteristic", // optional, default is null,
I thought maybe I can write something there - but if it's no used , so never mind.
what is 'heartrate' mean in the value section ?
NRF.setServices({ 0x180D: { // heart_rate 0x2A37: { // heart_rate_measurement notify: true, value : [0x06, heartrate], } } }, { advertise: [ '180D' ] });
does it tell that the data is bpm ? - if I'm correct :
where can I find a list of what I can put \ which values?can I say I'm sending temperature using
value = [0x1d, temperature]
then when I will read the data it will change it to C and I will see 29 ?
3.5 what will be if I'm sending heartrate using my own UUID ?
Thanks ,
- I guess I need to convert the 0x1D to 29 using some java hex to DEC function ?
-
-
Ok I will try it today ,
some more "basic" questions
- I'm trying to change the description of the UUID, but I get unknown all the time
I want to send the temperature - but when I read I get "1D" - what do I need to change so it will know it's temperature value and now byte data?
NRF.setServices({ "3e440001-f5bb-357d-719d-179272e4d4d9": { "3e440002-f5bb-357d-719d-179272e4d4d9": { description: "My_LED_UUID", // optional, default is null, writable : true, readable : true, notify: true, maxLen : 10, value : "Setup_Data", onWrite : function(evt) { data = evt.data[0]; if (data < 18) { digitalWrite(LED, 1); digitalWrite(Relay_Pin, 1); } else { digitalWrite(LED, 0); digitalWrite(Relay_Pin, 0);} } }, "3e440008-f5bb-357d-719d-179272e4d4d9": { description: "Device_Temp", // optional, default is null, readable : true, notify: true, value : [E.getTemperature()] } } }, {}); setInterval(function() { NRF.updateServices({ "3e440001-f5bb-357d-719d-179272e4d4d9" : { "3e440002-f5bb-357d-719d-179272e4d4d9" : { value : [data],//to be able to see that read is correct notify: true }, "3e440008-f5bb-357d-719d-179272e4d4d9" : { value : [E.getTemperature()],//to be able to see that read is correct notify: true } } }); }, 5000);
what am I missing?
Thanks ,
- I'm trying to change the description of the UUID, but I get unknown all the time
-
-
-
Ok
so we are on the right way :-)security question (before I continue with the python)
is there any way I can secure the connection ?
I will explain
right now
if someone will take a computer and run "Espruino Web IDE", scan - he will see my device.
and then he will be able to connect to him and do what evert he want - right?
(the same way I'm running now and uploading the code).
How can I make him request password before connecting ?and another question
can I use this security (password) in order to connect to the device and read the data ?
I want only verified devices to be able to read the Espruino data
right now any one can connect and readThanks,
-
first of all
thank you fir the help so far , you don't need to apologize :-)this is what I have now :
- created a device called "Test_Read_Write" - I can see it on BLE Scan
- I have open "nRf" on by Android device and mange to connect to it .
sending < 18 - led is on , > 18 led is off - so communication is working. I'm trying to add update service , did I do it right ?
I can see the data is changing when I send something to the device
but is there a function I can call to update the value only after the data is change?
and not print it once every 1000mSec (like I did)?
it will be better no ?My_MAC = NRF.getAddress(); print("My MAC address is " , My_MAC); var n = 0; NRF.setAdvertising({}, {name:"Test_Read_Write1"}); NRF.setServices({ "3e440001-f5bb-357d-719d-179272e4d4d9": { "3e440002-f5bb-357d-719d-179272e4d4d9": { writable : true, maxLen : 5, onWrite : function(evt) { n = evt.data[0]; if (n < 18) { digitalWrite(LED, 1); } else { digitalWrite(LED, 0);} } }, "3e440003-f5bb-357d-719d-179272e4d4d9": { readable : true, notify: true, value : ["hello"] } } }, {}); setInterval(function() { NRF.updateServices({ "3e440001-f5bb-357d-719d-179272e4d4d9" : { "3e440003-f5bb-357d-719d-179272e4d4d9" : { value : [n], notify: true } } }); }, 1000); // On disconnect, turn off led NRF.on('disconnect', function() { digitalWrite(LED, 0); });
when I upload the code I see this error :
BLE Connected, queueing BLE restart for later Uncaught Error: Can't update services until BLE restart at line 37 col 2 in .bootcde
is this OK ? or does it mean I have a problem ?
***after I will see everything is working on with my phone , I will need your help with the python error of sending data
Thanks ,
- created a device called "Test_Read_Write" - I can see it on BLE Scan
-
I have mange to work and took an working example from here:
https://www.espruino.com/BLE+Communicationsthis is the code I have wrote:
My_MAC = NRF.getAddress(); print("My MAC address is " , My_MAC); var n = "0"; NRF.setServices({ "3e440001-f5bb-357d-719d-179272e4d4d9": { "3e440002-f5bb-357d-719d-179272e4d4d9": { writable : true, onWrite : function(evt) { n = evt.data[0]; if (n < 18) { digitalWrite(LED, 1); } else { digitalWrite(LED, 0);} } }, "3e440003-f5bb-357d-719d-179272e4d4d9": { readable : true, value : [getTime()] } } }, {}); // On disconnect, turn off led NRF.on('disconnect', function() { digitalWrite(LED, 0); }); NRF.setAdvertising({}, {name:"Test_Read_Write"});
when I connect using android phone "nRF Connect "
I can see I have 2 chars from 1 service
3e440002 is write
3e440003 is readI have 3 questions :
when I connect to the 3e440002 - and send any byte - LED is on (which is good for me to understand how things works )
when I connect to 3e440003 - he only show me "4C 'L'"- what do I need to do in order to see "live" data (timestamp - just to see it's alive), or even the latest byte I sent to the device?
- is there any to see console.print while I'm connecting using web ide on my computer?
or do I have to connect it using serial cables? when I use a python code to send data I get this error:
Characteristic 3e440002-f5bb-357d-719d-179272e4d4d9 does not support write operations!
when I use the same code to connect to Arduino with the same chars - I can send data to it ,
also as I mention before - on android nRF I can send messagesso what am I missing ?
Thanks ,
- what do I need to do in order to see "live" data (timestamp - just to see it's alive), or even the latest byte I sent to the device?
-
Hello,
I have a simple project I want to run and want to know if I can use the MDBT42Q
I want to see I understand the configuration correct:- PI4 will be able to connect to him and send it 2 simple messages ("0" \ "1"), the it will change the digital output of 1 selected Digital pin(that will be connected to relay ) .
so the PI is the client and the MDBT42Q will be the server , right ? - what is the approximately~ distance I can use for communication ?
- can I connect an external antenna to the MDBT42Q and see if it's make any changes?
- I have a working code on Arduino BLE( my problem with the Arduino is the distance , I get around ~ 4 meters only ), can I publish the code here and get some help converting it to java?
Thanks,
- PI4 will be able to connect to him and send it 2 simple messages ("0" \ "1"), the it will change the digital output of 1 selected Digital pin(that will be connected to relay ) .
-
I know the problem is on my side ....
so maybe you can guide me to understanding
all I want to do is connect from the PI to the device and turn on\off led1this is what I'm missing :
1.up until now when I wanted to turn LED1 on I wrote
LED1.write(true)
and now you say I need to write 'LED1.set()\n' - do I need to add true\false ?- after I have connected to the device , why can't I see the data I'm sending to him , is there any way to write something to log in order to see where is the problem ?
all I can see is -> Bluetooth
I'm sending sample data once every 10 seconds , and I can't see anything - why?
I read somewhere I can use Node-RED for creating a project and connecting with the MDB42Q
I mange to create a connection and I'm sending data from it - but again, I don't see anything on the device - the led is not tuen on\off
do you have an example\guide for it? - after I have connected to the device , why can't I see the data I'm sending to him , is there any way to write something to log in order to see where is the problem ?
-
I think we misunderstanding each other.... :-)
can you show an example code to put on the mdb42q
all I want it to do it to be connactable from 1 knonwn MAC address and wait for message
I don't need it to send\advertise\publish nothingjust to be connected and wait for message
this is what I have done :
console.log("Startup"); NRF.setAdvertising([ {//here I put the HEX data -https://www.bluetooth.com/specifications/gatt/characteristics/ } ], { //here I put the defualt data ONLY! name : "Devcie TEST", showName: true, discoverable : true, connectable : true, scannable : true, interval:100 });
I can see the device in scanning
I mange to connect to him - because I can see this in the IDE :-> Bluetooth
and on my PI I can see I'm connected
now what I need to add in order to read the data I'm sending from the PI (sending json {'open'})
Thank you ,
-
-
-
-
maybe I didn't explain correct
I have connected to the mdb42q a LED in GPIO D15 (it this OK?)
I want to control the LED from the PI
I have the MAC address of the PI - I want it to connect only to it
DC::32::9A:**I have found this - and I can see it connect to the pi
var gatt; NRF.connect(" DC:**:32:**:9A:**").then(function(g) { gatt = g; }).then(function(service) { console.log("connected"); return gatt.startBonding(); }).then(function() { gatt.disconnect(); console.log("Done!"); });
what else do I need to write in order to make hi m"wait" for my command ON\Off?
and do you have an exapmle what need to do on the pi side?
-
Hello,
I want to connect to the mdb42q from my pi and be able to send him 2 types of messages to light up 2 ciruict (let's make it simple - want to control 2 gpio "1"\"0" from the pi)is there a guide \ example I can follow ?
also can I make a secure connection, meaning allow to connect only from known MAC address only?
so only my Pi will be able to connect to the device ?Thanks,
I have try this example
var gatt; NRF.requestDevice({ filters: [{ name: 'PI4' }] }).then(function(device) { console.log("found device"); return device.gatt.connect(); }).then(function(g) { gatt = g; console.log("connected"); return gatt.startBonding(); }).then(function() { console.log("bonded", gatt.getSecurityStatus()); gatt.disconnect(); }).catch(function(e) { console.log("ERROR",e); });
My pi name is PI4 - I can see it in bluetooth and ble scan from my phone
so what is wrong? missing?have try namePrefix: 'PI4'
have also try to use th service I used which is '1322' - get the same resualtNRF.requestDevice({ filters: [{services: ['1322'] }] }).then(function(device) {
ERROR No device found matching filters
-
-
no
the device is connected using serial TX\RX pins to a serail device that connect to the internet .
If I choose the COM of the device from my computer on the IDE - I can upload\see the MDBT42 .
my question is if I can upload new code not using the IDE \ using some kind of API
or maybe (just thought about it) send a command to the MDBT42 and tell him to download a new code ?
is there such a thing?
** No is also a good answer :-)Thanks ,
Ok
Thanks
it seem that now everything is working for me (almost),
I will continue working - and if I will have more question I will ask.
Thank you very much for the help!