-
Hi, with the custom firmware everything works perfectly!
After flashing, following these directions: https://github.com/pvvx/ATC_MiThermometer
@Vlad's code fetches values without problems:
var temp = null; var humidity = null; var battery = null; function getSensorData() { NRF.findDevices(function(devices) { if (devices[0] && devices[0].serviceData.fe95) { var data = devices[0].serviceData.fe95; // console.log(data); var flag = data[11]; // console.log(flag); switch (flag) { case 4: { // temp temp = (data[14] | data[15] << 8) / 10; break; } case 6: { // humidity humidity = (data[14] | data[15] << 8) / 10; break; } case 10: { // battery battery = devices[0].serviceData.fe95[14]; break; } case 13: { // temp and humidity temp = (data[14] | data[15] << 8) / 10; humidity = (data[16] | data[17] << 8) / 10; break; } default : { print("Unknown flag: " + flag); } } } for (var i = 0; i < devices.length; i++) { devices[i] = null; } devices = null; }, { filters: [ {serviceData:{"fe95":{}}} ], timeout: 2000 } ); } setInterval(function () { print("Temp: " + temp + " humidity: " + humidity + " battery: " + battery); getSensorData(); }, 5000);
THANK YOU ALL!
-
Hi @fanoush, you are right, in the next few days I will hack one :-)
See you soon!
-
Hi @fanoush, thanks for the link, I initially saw something about: https://github.com/atc1441/ATC_MiThermometer
Then I saw that through Python, without any hacks, you can get the values easily.
Maybe later, I sacrifice one in the name of science :-)
-
Hi @Gordon, I uploaded this code to Pixl.js (2v08)
var deviceInfo = {}; function parseDevice(device) { var d = new DataView(device.serviceData["fe95"]); var frame = d.getUint16(0, true); var offset = 5; console.log("FRAME: " + frame); if (frame&16) offset+=6; // mac address if (frame&32) offset+=1; // capabilitities if (frame&64) { // event var l = d.getUint8(offset+2); var code = d.getUint16(offset,true); if (!deviceInfo[device.id]) deviceInfo[device.id]={id:device.id}; event = deviceInfo[device.id]; switch (code) { case 0x1004: event.temperature = d.getInt16(offset+3,true)/10; break; case 0x1006: event.humidity = d.getInt16(offset+3)/10; break; case 0x100D: event.temperature = d.getInt16(offset+3,true)/10; event.humidity = d.getInt16(offset+5)/10; break; case 0x1008: event.moisture = d.getUint8(offset+3); break; case 0x1009: event.fertility = d.getUint16(offset+3,true)/10; break; // case 0x1007: break; // 3 bytes? got 84,0,0 or 68,0,0 default: event.code = code; event.raw = new Uint8Array(d.buffer, offset+3, l); break; } print(event); } }; setInterval(function () { NRF.setScan(parseDevice, { filters: [{serviceData:{"fe95":{}}}], timeout: 2000 }); }, 5000);
It always prints FRAME, and when the temperature or humidity changes it prints the event:
FRAME: 22616 { "id": "a5:c2:83:xx:xx:xx public", "code": 50578, "raw": new Uint8Array([208, 117, 0, 0, 58, 221, 132, 170, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) } FRAME: 22616 { "id": "a5:c2:83:xx:xx:xx public", "code": 15670, "raw": new Uint8Array([121, 182, 117, 0, 0, 185, 254, 166, 227, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
I have no idea how to extract the temperature and humidity :-)
Can I get some useful info from this Python code (0x80, 0x7F)?
THANK YOU
-
Hi @Gordon, thanks for the reply.
As soon as I have time, I try the code on my Pixl.js and tell you!
See you soon :-)
-
I have a Xiaomi LYWSD03MMC Thermometer / Hygrometer and with this CircuitPython library I can fetch its values:
Now I'd like to make everything work on Espruino thanks to your code.
I changed filters: [{serviceData: {"fe95": {}}}] the device is found (although its serviceData should be "ebe0ccb0") but all values remain null.
How do you think it could be solved?
THANK YOU
-
-
-
-
Hi fanoush, I haven't changed anything, I switched from MicroPython to espruino_2v04_microbit.hex via drag n drop: https://www.espruino.com/binaries/espruino_2v04_microbit.hex
:-(
THANK YOU
-
Hi everyone, I would like to upgrade my Micro:bit from version 2.04 to 2.06, but I noticed that both with different USB cables on both Mac and Windows (with related drivers) flash memory never loads ... and RESET button doesn't work either!
The example code loaded via BLE works fine, but for saving to flash permanently I am forced to reset(true); save();
Saving via IDE to "Flash" gives me error: Uncaught Error: Module Storage not found ... require("Storage").write(".bootcde","var on = false;\nsetIn
Do you know how to make flash memory reappear on desktop?
Here are some more info, THANK YOU for your collaboration!
"VERSION": "2v04", "GIT_COMMIT": "3956264e", "BOARD": "MICROBIT", "FLASH": 262144, "RAM": 16384, "CONSOLE": "Bluetooth", "MODULES": "" "free": 269, "usage": 31, "total": 300, "history": 25, "gc": 0, "gctime": 3.20434570312, "stackEndAddress": 536884568, "flash_start": 0, "flash_binary_end": 258132, "flash_code_start": 260096, "flash_length": 262144
-
OK, now it works!
Gordon, allObjects thank you very much!For whoever needed, here is the code useful for testing ...
// Espruino WiFi // Web IDE > reset(true); Serial1.setup(9600, {rx: B7, tx: B6}); LED2.write(0); var WIFI_NAME = "NAME"; var WIFI_OPTIONS = {password: "PASSWORD"}; var wifi; function getString() { LED2.write(0); require("http").get("http://www.pur3.co.uk/hello.txt", function(res) { var doc = ""; res.on('data', function(d) { doc += d; }); // data res.on('close', function(d) { doc = doc.substring(0, 5); Serial1.println(doc); LED2.write(1); setTimeout(function (){LED2.write(0);}, 15000); }); // close }); // get }; function onInit() { USB.setConsole(1); clearInterval(); wifi = require("Wifi"); wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) { if (err) throw err; setInterval(getString, 30000); getString(); }); }; // Web IDE > save(); // Web IDE > disconnect // Connected to battery // MDBT42Q // Web IDE > reset(true); global.LED2 = D2; global.LED2.write(0); var count = 0; function updateBT(wifi) { count = count + 1; var data = E.toString(wifi + count); global.LED2.write(1); setTimeout(function (){global.LED2.write(0);}, 6000); NRF.setAdvertising({}, { name: "TEST", manufacturer: 0x590, manufacturerData: data, showName: true }); }; function onInit() { var cmd = ""; Bluetooth.setConsole(1); Serial1.setup(9600, {rx: D8, tx: D6}); Serial1.on('data', function (wifi) { cmd += wifi; var idx = cmd.indexOf("\r"); while (idx >= 0) { var line = cmd.substr(0, idx); line = line.substring(0, 5); line = line.toLowerCase(); cmd = cmd.substr(idx + 1); clearInterval(); setInterval(updateBT, 15000, line); updateBT(line); idx = cmd.indexOf("\r"); }; }); }; // Web IDE > save(); // Web IDE > disconnect // Connected to battery
-
-
-
Hi everyone,
I would like to create a bluetooth notification system,
by serial connection of an Espruino WiFi (connected to the internet) to an MDBT42Q.When I unplug them from the Web IDE console and power them on batteries (charged)
MDBT42Q gives me no feedback ...I think there is a problem with serial communication,
I have tested them separately and have never given me hardware / software problemsCould you help me understand where I'm wrong?
// Espruino WiFi // Web IDE > reset(true); Serial1.setup(9600, {rx: B7, tx: B6}); LED2.write(0); var WIFI_NAME = "NAME"; var WIFI_OPTIONS = {password : "PASSWORD"}; var wifi; function getString() { require("http").get("http://www.pur3.co.uk/hello.txt", function(res) { var doc = ""; res.on('data', function(d) { doc += d; }); // data res.on('close', function(d) { doc = doc.substring(0, 5); // Hello Serial1.println(doc); LED2.write(1); }); // close }); // get }; function onInit() { clearInterval(); wifi = require("Wifi"); wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) { if (err) throw err; setInterval(getString, 30000); getString(); }); }; // Web IDE > save(); // Web IDE > disconnect // Connected to battery // MDBT42Q // Web IDE > reset(true); global.LED2 = D2; function updateBT(wifi) { var data = E.toString(wifi); data = data.toLowerCase(); // hello if(data == "hello"){ global.LED2.write(1); NRF.setAdvertising({}, { name: "TEST", manufacturer: 0x590, manufacturerData: data, showName: true }); } else{}; }; function onInit() { var cmd = ""; Serial1.setup(9600, {rx: D8, tx: D6}); Serial1.on('data', function (wifi) { global.LED2.write(0); cmd += wifi; var idx = cmd.indexOf("\r"); while (idx >= 0) { var line = cmd.substr(0, idx); cmd = cmd.substr(idx + 1); clearInterval(); setInterval(updateBT, 15000, line); updateBT(line); idx = cmd.indexOf("\r"); }; }); }; // Web IDE > save(); // Web IDE > disconnect // Connected to battery // Espruino WiFi > LED green (Hello) // MDBT42Q > ???
-
-
Hi everyone,
I would like to use this Joystick: https://www.adafruit.com/product/512
with the Espruino WiFi (2v02), it currently works on Feather M4 Express (CircuitPython):import ... stickY = analogio.AnalogIn(board.A0) # analog stickX = analogio.AnalogIn(board.A1) # analog stickSelect = DigitalInOut(board.A2) # digital stickSelect.direction = Direction.INPUT stickSelect.pull = Pull.UP while True: ... yValue = stickY.value ... xValue = stickX.value ... selectValue = stickSelect.value ... if yValue > 90 and yValue < 32000: print("Y DOWN") ... elif yValue > 40000 and yValue < 65500: print("Y UP") ... elif xValue > 90 and xValue < 32000: print("X LEFT") ... elif xValue > 40000 and xValue < 65500: print("X RIGHT") ... elif selectValue == False: print("PRESS") ... else: pass
In JavaScript I'm doing tests, Y and X both are recognized at '50 %' (yes UP and LEFT, no DOWN and RIGHT) ...
var BTN = {Y: A0, X: A1, SELECT: B10}; pinMode(BTN.Y, "input_pulldown"); pinMode(BTN.X, "input_pulldown"); pinMode(BTN.SELECT, "input_pulldown"); // (auto, input_pulldown and input_pullup) => NOT WORK while(true){ if (BTN.Y.read()){console.log("Y");} else if (BTN.X.read()){console.log("X");} else if (BTN.SELECT.read()){console.log("SELECT");} else {}; };
What do you think I can solve?
THANK YOU
Twitter.com/saraceni_andrea