• I just inlined the Amperka module (and made a version of ledHandling) and uploaded, but it uploads just fine for me with the latest EspruinoWiFi firmware:

    Modules.addCached("water-flow",function(­) {
      
    var WaterFlow = function(pin, opts) {
      this._pin = pin;
    
      this._pin.mode('input_pulldown');
    
      this._litres = 0;
      this._pulses = 0;
    
      this._pulseTimerID = null;
    
      this._speed = 0;
    
      opts = opts || {};
    
      this._avg = opts.averageLength || 10;
      this._pulsesPerLitre = opts.pulsesPerLitre || 450;
      this._minimumSpeed = opts.minimumSpeed || 1;
    
      this._litresPerPulse = 1 / this._pulsesPerLitre;
      this._speedNumerator = this._litresPerPulse * this._avg;
      this._updatePeriod = (60 * 1000) / (this._minimumSpeed * this._pulsesPerLitre);
    
      this._avgArray = new Array(this._avg); // [litres per second]
      this._avgIterator = 0;
    
      this.reset();
    
      this._watch();
    };
    
    WaterFlow.prototype._watch = function() {
      setWatch(this._onChange.bind(this), this._pin, {
        repeat: true,
        edge: 'rising',
        debounce: 1
      });
    };
    
    WaterFlow.prototype._average = function() {
    
      this._avgArray[this._avgIterator] = getTime();
    
      var last;
      if (this._avgIterator === this._avg - 1) {
        last = this._avgArray[0];
      } else {
        last = this._avgArray[this._avgIterator + 1];
      }
    
      var speed = this._speedNumerator / (this._avgArray[this._avgIterator] - last);
    
      if (++this._avgIterator === this._avg) {
        this._avgIterator = 0;
      }
    
      return speed;
    };
    
    WaterFlow.prototype._onChange = function() {
      this._pulses++;
      this._litres += this._litresPerPulse;
    
      if (this._pulseTimerID !== null) {
        clearTimeout(this._pulseTimerID);
        this._pulseTimerID = null;
        this._speed = this._average();
      }
    
      var self = this;
      this._pulseTimerID = setTimeout(function() {
        self._pulseTimerID = null;
        self._speed = 0;
        self.emit('drain');
      }, this._updatePeriod);
    
      this.emit('pulse');
    };
    
    WaterFlow.prototype.volume = function(units) {
      switch (units) {
        case 'l': return this._litres;
        case 'cm^3': return this._litres * 1000;
        case 'm^3': return this._litres / 1000;
        default: return this._litres;
      }
    };
    
    WaterFlow.prototype.reset = function() {
      var time = getTime();
      for (var i = 0; i < this._avg; ++i) {
        this._avgArray[i] = time;
      }
      this._litres = 0;
      this._pulses = 0;
    };
    
    WaterFlow.prototype.speed = function(units) {
      switch (units) {
        case 'l/min': return this._speed * 60;
        case 'cm^3/min': return this._speed * 60 * 1000;
        case 'm^3/min': return this._speed * 60 / 1000;
        default: return this._speed * 60;
      }
    };
    
    exports.connect = function(pin, opts) {
      return new WaterFlow(pin, opts);
    };
    });
    Modules.addCached("ledHandling",function­() {
      exports = function(pin) {
        return {
          blink:function(){ digitalPulse(pin,1,100); },
          On:function(){ pin.set();},
          Off:function(){ pin.reset(); },
        };
      };
    });
    
    
    var HOSTS = ["192.168.1.92", "192.168.1.93", "192.168.1.95"];
    var WIFI = [
      ["Alhimik" , { password : "" } ],  //0
      ["Alhimik_N", { password : "" }],  //1
      ["A-Alhimik ", { password : "" }]  //2
    ];
    var INIT_OPTIONS = {"HOSTS": [0], 'WIFI': 0, 'ISSTART': 0, "Name": 'EspWater'};
    var wifi = require("EspruinoWiFi");
    var L = {
      'LED1': require("ledHandling")(LED1),
      'LED2': require("ledHandling")(LED2),
      'A5': require("ledHandling")(A5, 1),
      'A6': require("ledHandling")(A6, 1),
      'A7': require("ledHandling")(A7),
      'B1': require("ledHandling")(B1)
    };
    E.on('init', function() {
      USB.setConsole();
      console.log('started');
      L.LED1.On();
      //INIT_OPTIONS.ISSTART = 1;
      setTimeout(wifiOn, 1000);
    });
    var wifiOn = function(){
      console.log('starting WiFi');
      console.log(WIFI[INIT_OPTIONS.WIFI][0] + ' - ' + WIFI[INIT_OPTIONS.WIFI][1]);
      wifi.connect(WIFI[INIT_OPTIONS.WIFI][0],­ WIFI[INIT_OPTIONS.WIFI][1], function(err) {
        if (err) {
          console.log("Connection error: "+err);
          L.LED1.blink(50);
          setTimeout(wifiOn, 60000);
          return;
        }
        console.log("WiFi connected!");
        L.LED1.On(0); L.LED2.blink(100);
        for (var i in INIT_OPTIONS.HOSTS) {
          setTimeout(ccon, 5000 * i, INIT_OPTIONS.HOSTS[i]);
        }
      });
      return;
    };
    /*********
     FLOW-Sensor
     **********/
     var flowSensor = [];
     flowSensor[0]  = require('water-flow').connect(A0, {measurePeriod: 5});
     flowSensor[1]  = require('water-flow').connect(A1, {measurePeriod: 5});
    

    I can't see anything in there that'd cause problems either - unless there was loads of water (100ml/sec) flowing through your water flow sensors.

    Can you try calling require("Storage").eraseAll()? It's possible that you had some code saved (with 'save on send, even after reset') that's doing something in the background that is causing problems.

  • Big thanks for your respond. I will have a look on the problem on weekends and will try to determine the problem more precisely.

About

Avatar for Vladimir @Vladimir started