hlapp/wirelesstags-js

Set state example

Closed this issue · 9 comments

All the examples I've found are about how to get data or read a tag's state, but I can't figure out how to change a tag's state. Specifically, I'm trying to reset a tag's state from 'Movement Detected' to 'Timed Out'. Is this even possbile?

hlapp commented

Yes, you can do that from the app, and it's actually documented in the API: ResetTag

And here is the JavaScript method used by the web app

function resetit(btn, wid) {
	var tag = taglist_cache[wid];
	var oldhtml = show_finding(btn);
	$.ajax({
		url: WSROOT + "ethClient.asmx/ResetTag",
		data: "{id: '" + tag.slaveId + "'}",
		headers: allTagManager ? { 'X-Set-Mac': tag.mac } : null,
		success: function (retval, textStatus) {
			restore_finding(btn, oldhtml);
			updateTag(retval.d);
		},
		error: function (xhr, textStatus, exception) {
			popup_error(xhr, btn, null, exception.message);
			restore_finding(btn, oldhtml);
		}
	});
}

We can disregard the btn variable, all we need is the id of the tag.

hlapp commented
hlapp commented

Pull request is up. @ahmadtawakol which release series are you using? I think I can back port this to 0.6.x, but am not sure about earlier than that. (The pull request is for the 0.7.0-beta pre-release, which is not on npm yet.)

Thank you! This is perfect. I'm not running wirelesstags-js yet, so I'm not on any release. Can I install it directly from git? Or does it have to be on npm?

hlapp commented

Absolutely, you can install from git. I suppose this means I don't need to bother with backporting, it'll just become a new feature of the 0.7.x series.

(Your only risk in installing directly from Git is that if you install from master, a later update may jump you to a new minor or even major version than the one you were on, which may change some of the API's signatures or behavior. You can prevent this by installing from a commit (if you use npm). If installing from the npm repository, npm allows you to say which version is eligible for being upgraded to.)

I tried installing from git yesterday, but I kept getting lots of errors which were all full of "nan", even the directory names and the files were all called "nan". I don't have my laptop with me right now, so I'll try again tonight and send you the full errors

Ok, never mind my last post. Turns out that I needed to install gcc 4.8 and set it as the default gcc, I was on 4.6.

I installed this package from the commit you made. I tested it out and already implemented in my project, and it works perfectly, this is exactly what I needed. Thank you again for adding this.

hlapp commented

Glad it works for you! Post an issue if something doesn't seem to work as advertised.