I would like to control web things from a web page.
I’m able to get property this is my code:
var url = “https://***.mozilla-iot.org/things/gpio-20/properties/on”;
try {
var mzreq = new XMLHttpRequest();
mzreq .open(“GET”, url, false);
mzreq .setRequestHeader(‘Accept’, ‘application/json’);
mzreq .setRequestHeader(‘Authorization’, ‘Bearer eyJ…’);
mzreq .onreadystatechange = function () {
if (mzreq .readyState === 4) {
if (mzreq .status === 200 || mzreq .status == 0) {
var allText = mzreq .responseText;
alert(allText);
}
}
}
mzreq .send(null);
}
catch (err) {
alert(err);
}
but i’m not able to set property value:
var url = “https://***.mozilla-iot.org/things/gpio-20/properties/on”;
try {
var mzreq = new XMLHttpRequest();
mzreq .open(“PUT”, file, true);
mzreq .setRequestHeader(‘Accept’, ‘application/json’);
mzreq .setRequestHeader(‘Authorization’, ‘Bearer eyJ…’);
mzreq .onreadystatechange = function () {
if (mzreq .readyState === 4) {
if (mzreq .status === 200 || mzreq .status == 0) {
var allText = mzreq .responseText;
alert(allText);
}
}
}
mzreq .send(’{ “on”: true }’);
}
catch (err) {
alert(err);
}
I get response 400.
P.S.:
I have installed gateway manually from github, not from pre-built image.