ds18b20

Posted on
  • Any implementation works poorly, each approach has different problems
    this example by https://www.espruino.com/DS18B20

    owMultiSensors = new OneWire(D4);
    DSlib = require("DS18B20") ; 
    var sensors = owMultiSensors.search().map(function (device) {
        return DSlib.connect(owMultiSensors, device);
      });
     
      setInterval(function() {
        sensors.forEach(function (sensor, index) {
        sensor.getTemp(function (temp) {
          console.log(index + ": " + temp + "°C");
        });
      });
    
    }, 1000);
    
    

    After several seconds the error:

    ASSERT(jsvGetLocks(var) < 15) FAILED AT src/jsvar.c:721
      #1[r3,l2] Object {
        #2[r1,l2] ASSERT(jsvGetLocks(var) < 15) FAILED AT src/jsvar.c:701
    HALTING.
    

    If sensors search put to set Interval this problem disappears , but other appears

    owMultiSensors = new OneWire(D4);
    DSlib = require("DS18B20") ; 
    setInterval(function() {
      var sensors = owMultiSensors.search().map(function (device) {
        return DSlib.connect(owMultiSensors, device);
      });
        sensors.forEach(function (sensor, index) {
        sensor.getTemp(function (temp) {
          console.log(index + ": " + temp + "°C");
        });
      });
    }, 1000);
    

    This code fills all RAM in time and device stops working
    Interval time increase does not have any influence, it only delays the time of crash

  • does anyone have any ideas how to fix this?

  • Sat 2021.02.20

    How many sensors are attempted to be traversed using the forEach?


    'does anyone have any ideas how to fix this'

    I do not have this hardware sensor. I do however note the following:



    When L5 in the second code snippet was inserted inside the setInterval(), a connect object is being created once each second. Eventually memory runs out as has been discovered.

    From your link

    https://www.espruino.com/DS18B20

    beneath heading 'Multiple sensors' uses an array of exactly three connect objects to which the data reads are applied.

    Has the code in that section been used verbatim and what were those results?



    The module source is here, if that helps

    https://www.espruino.com/modules/DS18B20­.js

    Function getTemp() uses a callback which potentially could be null and setTimeout() function call.

    Does lengthening the interval in L14 reduce the number of ASSERT's?

  • How many sensors are attempted to be traversed using the forEach?

    About 8 sensors.

    I do not know enithing , i only use code from example

  • Sun 2021.02.21

    re post #3 'Has the code in that section been used verbatim and what were those results?'
    re post #4 'i only use code from example'

    L3 of the first code block in post #1 does not match the three sections below heading 'Multiple sensors' as the 'sensors' array definition is missing.

    My inquiry was to see what errors occurred when using those three code blocks. ( me thinks none )

    To prove this to yourself, add a console.log( "Line 6: " + sensors ); (modify to your choosing) statement at L6 of the first code block to determine if your eight sensors are recognized.


    re: 'I do not know enithing' (sic)

    May I ask how many years of Javascript & coding experience you have so that we may provide other tutorials to assist.

  • I'em frontend developer, and I know JS pretty well.

    everything works, the sensors are detected. The problem is that in one example ASSERT is an error, in the second one runs out of memory.
    you don't even need to look at my code, the same problem will be copying the example from the espuino website

    ASSERT(jsvGetLocks(var) < 15) FAILED AT src/jsvar.c:721
    

    this error also occurs if you call the ws.send("....") 15 times (by https://www.espruino.com/ws#websocket-se­rver)

    ....
    var server = require('ws').createServer(onPageRequest­);
    var clients = [];
    server.listen(8000);
    server.on("websocket", function(ws) {
        clients.push(ws);
        ws.on('message',function(msg) { print("[WS] "+JSON.stringify(msg)); });
        ws.send("Hello from Espruino!");
    });
    
    
      setInterval(function(){
        clients.forEach(ws => ws.send('....'));
    //after 14 events ERROR ASSERT(jsvGetLocks(var) < 15) FAILED AT src/jsvar.c:721 
      },5000);
    
    .....
    

    This dirty example helps, but not nice

      setInterval(function(){
          var cc = clients.map(ws => {
            ws.send('....');
            return ws.clone();
          } );
          clients =cc;
        
      },5000);
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

ds18b20

Posted by Avatar for user125091 @user125091

Actions