• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

MM_Withings module | Values are not being updated

Scheduled Pinned Locked Moved Troubleshooting
1 Posts 1 Posters 818 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    Fab2k
    last edited by Mar 19, 2017, 1:03 PM

    Hey everyone,

    this is my first post, so hopefully this is the correct category.

    I have an issue with the MM_Withings module from john7002 . Access to the API works fine and I can see the extracted value in the Log.

    But unfortunately the table does not get updated accordingly.

    I am not a JavaScript expert and am kind of desperate.

    I stripped down the original MM_Withings.js to just handle the received weight. I attached the code.

    It would be great, if you could check the code and point me in the right direction.

    Thanks in advance for your efforts.

      // init method
      start: function() {
        this.α = 0;
        // set interval for reload timer
        this.t = this.config.updateInterval * 60 * 1000 / 360;
        this.weight=0;
        Log.info(this.name + " 1st step of execution.");
    
        this.updateLoad();
      },
    
      updateLoad: function() {
        Log.info(this.name + "refresh triggered");
        var that = this;
    
        return Q.fcall(
          this.load.get_URL.bind(that,'weight'),
          Log.info("URL LOADED"),
          this.renderError.bind(that)
        ).then(
            this.extractweight.bind(that), //weight
    	Log.info("WEIGHT EXTRACTED"),
            this.renderError.bind(that)
        ).done(
    	this.updateWait.bind(that),
    	Log.info("BIND UPDATE WEIGHT")
        );
    
      },
    
      updateWait: function() {
        this.α++;
        this.α %= 360;
        var r = (this.α * Math.PI / 180);
    
        if (r === 0) {
          // refresh data
          this.updateLoad();
        } else {
          // wait further
          setTimeout(this.updateWait.bind(this), this.t);
        }
      },
    
      load: {
        get_URL: function(data_type) {
          switch(data_type){
            case 'weight':
              base= this.config.api.base;
              base2=this.config.api.measure_weight;
              end=this.config.api.authPayload_weight;
              break;
            default:
              return '';
            }
    
            return Q($.ajax({
              type: 'POST',
              url: base+base2,
              data: this.config.api.authPayload.format(
                  this.config.oauth_consumer_key,
                  Array(32+1).join((Math.random().toString(36)+'00000000000000000').slice(2, 18)).slice(0, 32),
                  this.config.oauth_signature)+
                  this.config.api.authPayload2.format(
                  Date.now(),
                  this.config.oauth_token,
                  this.config.oauth_signature)+
                  this.config.api.authPayload3.format(
                  this.config.clientID)+end
            }));
    
    
    
          },
      },
    
      extractweight: function(data) {
        var var2=data;
        var obj = JSON.parse(data);
        Log.info("status=" + obj.status);
        Log.info("time=" +obj.body.measuregrps[0].date);
        this.weight=obj.body.measuregrps[0].measures[0].value*Math.pow(10,obj.body.measuregrps[0].measures[0].unit);
        this.dateweight=obj.body.measuregrps[0].date;
    
        Log.info("poids=" +this.weight + "; date=" + this.dateweight);
      },
    
      renderError: function(reason) {
        console.log("error " + reason);
      },
    
      getScripts: function() {
        return [
          'String.format.js',
          '//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.js',
          'jquery-2.2.2.js',
          'q.min.js',
          'moment.js'
        ];
      },
    
      getDom: function() {
        Log.info("UPDATE WEIGHT: " +this.weight + " DOM");
        return $('<div>' + '<table> <tr><td> Gewicht: ' + this.weight +' kg</td></tr></table></div>')[0];
    
      }
    });
    
    
    1 Reply Last reply Reply Quote 0
    • 1 / 1
    1 / 1
    • First post
      1/1
      Last post
    Enjoying MagicMirror? Please consider a donation!
    MagicMirror created by Michael Teeuw.
    Forum managed by Sam, technical setup by Karsten.
    This forum is using NodeBB as its core | Contributors
    Contact | Privacy Policy