Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
aymen-mouelhi committed Mar 3, 2017
1 parent cf0339c commit a54f791
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions db/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const notificationSchema = new mongoose.Schema({
type: Boolean,
required: true
},
connectorId: String,
status: String,
data: mongoose.Schema.Types.Mixed,
timestamp: String,
type: {
type: Boolean,
required: true
Expand Down
30 changes: 30 additions & 0 deletions examples/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ app.get('/api/stations/:id/restart', function(req, res){
});
});


app.get('/api/stations/:id/clearCache', function(req, res){
// Restart Station
var pointId = req.params.id;

Storage.findById('station', pointId, function(err, station){
if(err){
console.log('[http] Error: ' + err);
res.send(err);
}else{
if(station){
console.log('station: ' + JSON.stringify(station));
//var endpoint = station.endpoint || "192.168.0.114:8081";
console.log(`[OCPP Server] Clear Cache ${station.chargeBoxIdentity} on ${station.endpoint} ...`);

// create client
CentralSystemServer.createChargeBoxClient(station, function(){
console.log(`[ChargeBox] Client Created for ${station.chargeBoxIdentity}`);
CentralSystemServer.clearCache(station.chargeBoxIdentity, station.endpoint);
});
}else{
res.send({
error: 'station ' + pointId + ' is not found !'
})
}
}
});
});


var server = app.listen(app.get('port'), function(){
console.log('Server is running on port ' + app.get('port'));
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
"express": "^4.14.1",
"externalip": "^1.0.2",
"firebase": "^3.6.6",
"fs": "0.0.1-security",
"ip": "^1.1.4",
"ip-address": "^5.8.6",
"moment": "^2.17.1",
"mongoose": "^4.8.0",
"os": "^0.1.1",
"path": "^0.12.7",
"portfinder": "^1.0.12",
"promise": "^7.1.1",
Expand Down
12 changes: 11 additions & 1 deletion utils/SOAPWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,25 @@ class SOAPWrapper {
//TODO Check if port is used
server.listen(this.port, function() {
console.log(self._log() + ' ' + name + ' Server is listening on port ' + self.port);
var message = '/***********************************************************************/' + require("os").EOL;
require('fs').appendFile(require('path').resolve(__dirname, '../logs/soap.log'), message, function (err) {
if (err) throw err;
});
});

// SOAP Server listener
this.soapServer = soap.listen(server, this.path, this.services, this.xml);

if (this.log) {
var os = ;

this.soapServer.log = function(type, data) {
// type is 'received' or 'replied'
console.log(self._log() + ' [' + type + '] ' + JSON.stringify(data));
var message = self._log() + ' [' + type + '] ' + JSON.stringify(data) + require("os").EOL;
console.log(message);
require('fs').appendFile(require('path').resolve(__dirname, '../logs/soap.log'), message, function (err) {
if (err) throw err;
});
};
}

Expand Down

0 comments on commit a54f791

Please sign in to comment.