Trafic Light Sample Raspberry PI - aliconnect/aliconnect.sdk GitHub Wiki

Configure Atom Remote-Sync

{
    "logger": {
        "title": "Remote Sync"
    },
    "uploadOnSave": true,
    "useAtomicWrites": false,
    "deleteLocal": false,
    "hostname": "192.168.0.135",
    "port": "22",
    "ignore": [
        ".remote-sync.json",
        ".git/**"
    ],
    "target": "/home/pi/control",
    "username": "pi",
    "password": "PiPassword",
    "watch": [],
    "transport": "scp"
}

Edit file control1.js

const on = 0;
const off = 1;
aim.extend ({
    operations : {
        lfv_Verkeerslichten_Verkeersbuis_SetStand : function (id, stand) {
        	var vkl = aim.data.lfv_Verkeerslichten_Verkeersbuis[id];
            if (!vkl) return { status: 404 }; // Not Found
            var rio = i2c[vkl.i2c];
            if (!rio) return { status: 400 }; // Invalid ID
        	clearTimeout(this.to);
        	switch (stand) {
        		case "rood":
        			aim.digitalWrite(vkl.i2c, vkl.doGroen, off);
        			aim.digitalWrite(vkl.i2c, vkl.doGeel, on);
        			aim.digitalWrite(vkl.i2c, vkl.doRood, off);
        			this.to = setTimeout(function () {
        				aim.digitalWrite(vkl.i2c, vkl.doGroen, off);
        				aim.digitalWrite(vkl.i2c, vkl.doGeel, off);
        				aim.digitalWrite(vkl.i2c, vkl.doRood, on);
                        ws.request({ url: `lfv_Verkeerslichten_Verkeersbuis(${id})`, method: "PATCH", body: { stand: "rood" } }, function(res){ console.log('SET',res);});
        			}.bind(this), 3000);
                    ws.request({ url: `lfv_Verkeerslichten_Verkeersbuis(${id})`, method: "PATCH", body: { stand: "geel" } }, function(res){ console.log('SET',res);});
        			break;
                case "groen":
        			aim.digitalWrite(vkl.i2c, vkl.doGroen, on);
        			aim.digitalWrite(vkl.i2c, vkl.doGeel, off);
        			aim.digitalWrite(vkl.i2c, vkl.doRood, off);
                    ws.request({ url: `lfv_Verkeerslichten_Verkeersbuis(${id})`, method: "PATCH", body: { stand: "groen" } }, function(res){ console.log('SET',res);});
        			break;
                case "gedoofd":
        			aim.digitalWrite(vkl.i2c, vkl.doGroen, off);
        			aim.digitalWrite(vkl.i2c, vkl.doGeel, off);
        			aim.digitalWrite(vkl.i2c, vkl.doRood, off);
                    ws.request({ url: `lfv_Verkeerslichten_Verkeersbuis(${id})`, method: "PATCH", body: { stand: "gedoofd" } }, function(res){ console.log('SET',res);});
        			break;
        		case "geel_knipperen":
        			this.geel_knipperen = off;
        			(function () {
        				aim.digitalWrite(vkl.i2c, vkl.doGroen, off);
        				aim.digitalWrite(vkl.i2c, vkl.doGeel, this.geel_knipperen ^= 1);
                        aim.digitalWrite(vkl.i2c, vkl.doRood, off);
        				this.to = setTimeout(arguments.callee.bind(this), 1000);
        			}).call(this);
                    ws.request({ url: `lfv_Verkeerslichten_Verkeersbuis(${id})`, method: "PATCH", body: { stand: "geel_knipperen" } }, function(res){ console.log('SET',res);});
        			break;
        		default:
        	}
        	return { status: 200 }; // OK
        }
    }
});

AFter describing the API and the necessary software we will need to create a dara file with teh actual device infromation.

Create file lfv_Verkeerslichten_Verkeersbuis_data.json. Add the data.

  • "address": "0x20" all address pins pulled low
  • "device": "/dev/i2c-1" all address pins pulled low ...
{
    "i2c": {
        "1":{
            "address": "0x20",
            "device": "/dev/i2c-1",
            "debug": false
        }
    },
    "lfv_Verkeerslichten_Verkeersbuis": {
        "1": {
            "id": 12345,
            "i2c": 1,
            "doGroen" : 5,
            "doGeel" : 6,
            "doRood" : 7
        }
    }
}
⚠️ **GitHub.com Fallback** ⚠️