1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | var config = { host: "<peer id>-vp0.us.blockchain.ibm.com", port: "5003", secure_context: "<user id>", enroll_secret: "<enroll secret>", protocol: "https", debug_mode: true, chaincodeURL: "<peer id>-vp0.us.blockchain.ibm.com:5003/chaincode", name: blk_chaincode, path: blk_chaincode, messageId: "", contract_version: "1.0", timeout: 3000, template: { "jsonrpc": "2.0", "method": "{{method}}", "params": { "type": 1, "chaincodeID":{ "name":"mycc", }, "ctorMsg": { "function":"{{function}}", "args":[], }, "secureContext": "<user id>", }, "id": 0 }, }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | // Prepare the rest body for createAsset createBody.method = 'invoke'; createBody.params.ctorMsg.function = 'createAsset'; createBody.params.ctorMsg.args = ["{\"assetID\":\""+ input_vin +"\",\"ownerName\":\""+ input_ownerName +"\",\"createDate\":\""+ v_createdt +"\",\"numberPlate\":\""+ input_numberPlate +"\"}"]; // Call blockchain createAsset function using rest api https.request(options, function(res4) { res4.setEncoding('utf8'); res4.on('data', function (chunk) { console.log('BODY: ' + chunk); }); // Prepare the vehicle JSON structure for inserting into Cloudant var vehicle = { vin: input_vin, owner: input_ownerName, number: input_numberPlate, status: 'active', createDate: v_createdt }; var v_id = input_vin + ' - ' + input_numberPlate; // Insert the vehicle into Cloudant db.insert(vehicle, v_id, function(err, body, header) { if (err) { return console.log(v_id + ' -- [insert] ', err.message); } }); }).end(JSON.stringify(createBody)); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | deviceClient.connect(); deviceClient.on('connect', function(){ if(iotDeviceConnectionStatus == false) { iotDeviceConnectionStatus = true; var i=0; console.log("connected"); var IOTSent = setInterval(function sendIOTData() { if (i >= totalcount) { deviceClient.disconnect(); iotDeviceConnectionStatus = false; selectedVehicle.sim_status_id="1"; iotDataSent = true; clearInterval(IOTSent); return; } datatopublish.d = carprobesampledata; i++; processingStatus = "Capturing car data "+i+"/"+totalcount; console.log(processingStatus); var driveTimestamp = new Date().toISOString(); datatopublish.d.timestamp = drivedate + driveTimestamp.substr(10,driveTimestamp.length); datatopublish.d.trip_id = assetid+moment(new Date()).format('DD'); datatopublish.ts = drivedate + moment(new Date()).format('THH:mm:ss.SSSZZ'); deviceClient.publish('load', 'json', JSON.stringify(datatopublish), 0); },delay*800); console.log("End of on connect.."); } }); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |