I 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();
});
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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.png
I guess I will need to change the UUID also , no ?
Thanks ,
About my code
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?
Thank you again ,