Read the statement by Michael Teeuw here.
MM_Withings module | Values are not being updated
-
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]; } });
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login