This is the sample program that can see the decode result of barcode data on Watson IoT.

Dependencies:   AsciiFont DisplayApp GR-PEACH_video LCD_shield_config LWIPBP3595Interface_STA_for_mbed-os USBDevice

NODEFLOW_GR-PEACH.txt

Committer:
Osamu Nakamura
Date:
2016-11-10
Revision:
1:67f8b5cfde75
Parent:
0:7d720671e6dc

File content as of revision 1:67f8b5cfde75:

[{"id":"6e9a1f05.7f81","type":"ibmiot in","z":"b9758c03.a34b6","authentication":"apiKey","apiKey":"","inputType":"evt","deviceId":"MBED_ENDPOINT_NAME_GOES_HERE","applicationId":"","deviceType":"mbed-endpoint","eventType":"notify","commandType":"","format":"json","name":"barcode reader observations","service":"registered","allDevices":false,"allApplications":"","allDeviceTypes":false,"allEvents":false,"allCommands":"","allFormats":false,"qos":"0","x":430,"y":281.9440612792969,"wires":[["728ad60e.9bbce8"]]},{"id":"d5129024.164ca","type":"ibmiot out","z":"b9758c03.a34b6","authentication":"apiKey","apiKey":"","outputType":"cmd","deviceId":"MBED_ENDPOINT_NAME_GOES_HERE","deviceType":"mbed-endpoint","eventCommandType":"PUT","format":"json","data":"0","qos":"0","name":"set LED command (PUT)","service":"registered","x":911.0512084960938,"y":180.29727935791016,"wires":[]},{"id":"5f2c35f0.d739ac","type":"template","z":"b9758c03.a34b6","name":"LED ON","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{ \"resourceId\":\"311/0/5850\", \"payload\":\"MA==\", \"deviceId\":\"MBED_ENDPOINT_NAME_GOES_HERE\", \"method\":\"PUT\" }","x":676.7462158203125,"y":207.48011779785156,"wires":[["d5129024.164ca"]]},{"id":"93a4ebe7.356748","type":"template","z":"b9758c03.a34b6","name":"LED OFF","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{ \"resourceId\":\"311/0/5850\", \"payload\":\"MQ==\", \"deviceId\":\"MBED_ENDPOINT_NAME_GOES_HERE\", \"method\":\"PUT\" }","x":674.7817993164062,"y":154.6229705810547,"wires":[["d5129024.164ca"]]},{"id":"4a711f82.6011a","type":"debug","z":"b9758c03.a34b6","name":"","active":true,"console":"false","complete":"value","x":1155.380859375,"y":281.5078430175781,"wires":[]},{"id":"5dae42b3.312c2c","type":"inject","z":"b9758c03.a34b6","name":"Turn LED ON","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":409.90069580078125,"y":208.01576232910156,"wires":[["5f2c35f0.d739ac"]]},{"id":"d80b2f6b.25dfa","type":"inject","z":"b9758c03.a34b6","name":"Turn LED OFF","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":408.31353759765625,"y":154,"wires":[["93a4ebe7.356748"]]},{"id":"465a3acf.5bd724","type":"function","z":"b9758c03.a34b6","name":"Base64DecodeToValue","func":"var Base64 = {\n    _keyStr: \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\",\n    encode: function(e) {\n        var t = \"\";\n        var n, r, i, s, o, u, a;\n        var f = 0;\n        e = Base64._utf8_encode(e);\n        while (f < e.length) {\n            n = e.charCodeAt(f++);\n            r = e.charCodeAt(f++);\n            i = e.charCodeAt(f++);\n            s = n >> 2;\n            o = (n & 3) << 4 | r >> 4;\n            u = (r & 15) << 2 | i >> 6;\n            a = i & 63;\n            if (isNaN(r)) {\n                u = a = 64\n            } else if (isNaN(i)) {\n                a = 64\n            }\n            t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)\n        }\n        return t\n    },\n    decode: function(e) {\n        var t = \"\";\n        var n, r, i;\n        var s, o, u, a;\n        var f = 0;\n        e = e.replace(/[^A-Za-z0-9+/=]/g, \"\");\n        while (f < e.length) {\n            s = this._keyStr.indexOf(e.charAt(f++));\n            o = this._keyStr.indexOf(e.charAt(f++));\n            u = this._keyStr.indexOf(e.charAt(f++));\n            a = this._keyStr.indexOf(e.charAt(f++));\n            n = s << 2 | o >> 4;\n            r = (o & 15) << 4 | u >> 2;\n            i = (u & 3) << 6 | a;\n            t = t + String.fromCharCode(n);\n            if (u != 64) {\n                t = t + String.fromCharCode(r)\n            }\n            if (a != 64) {\n                t = t + String.fromCharCode(i)\n            }\n        }\n        t = Base64._utf8_decode(t);\n        return t\n    },\n    _utf8_encode: function(e) {\n        e = e.replace(/rn/g, \"n\");\n        var t = \"\";\n        for (var n = 0; n < e.length; n++) {\n            var r = e.charCodeAt(n);\n            if (r < 128) {\n                t += String.fromCharCode(r)\n            } else if (r > 127 && r < 2048) {\n                t += String.fromCharCode(r >> 6 | 192);\n                t += String.fromCharCode(r & 63 | 128)\n            } else {\n                t += String.fromCharCode(r >> 12 | 224);\n                t += String.fromCharCode(r >> 6 & 63 | 128);\n                t += String.fromCharCode(r & 63 | 128)\n            }\n        }\n        return t\n    },\n    _utf8_decode: function(e) {\n        var t = \"\";\n        var n = 0;\n        var r, c2;\n        while (n < e.length) {\n            r = e.charCodeAt(n);\n            if (r < 128) {\n                t += String.fromCharCode(r);\n                n++\n            } else if (r > 191 && r < 224) {\n                c2 = e.charCodeAt(n + 1);\n                t += String.fromCharCode((r & 31) << 6 | c2 & 63);\n                n += 2\n            } else {\n                c2 = e.charCodeAt(n + 1);\n                c3 = e.charCodeAt(n + 2);\n                t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);\n                n += 3\n            }\n        }\n        return t\n    }\n};\n\nvar str = Base64.decode(msg.payload.payload);\nreturn {\"value\":str};","outputs":1,"noerr":0,"x":910.8890991210938,"y":281.6666564941406,"wires":[["4a711f82.6011a"]]},{"id":"728ad60e.9bbce8","type":"switch","z":"b9758c03.a34b6","name":"Is Barcode Data?","property":"payload.path","propertyType":"msg","rules":[{"t":"eq","v":"/888/0/7700","vt":"str"}],"checkall":"true","outputs":1,"x":684.7778930664062,"y":281.6666564941406,"wires":[["465a3acf.5bd724"]]}]