first posts
This commit is contained in:
parent
0686e02b75
commit
88b2cf4212
26
dist/log.js
vendored
26
dist/log.js
vendored
@ -1,8 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const moment = require("moment");
|
const moment = require("moment");
|
||||||
const config = require("./config");
|
|
||||||
const nodemailer = require("nodemailer");
|
|
||||||
var Level;
|
var Level;
|
||||||
(function (Level) {
|
(function (Level) {
|
||||||
Level[Level["All"] = 0] = "All";
|
Level[Level["All"] = 0] = "All";
|
||||||
@ -29,30 +27,6 @@ function setLevel(value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.setLevel = setLevel;
|
exports.setLevel = setLevel;
|
||||||
function sendAlarmMail(subject, message) {
|
|
||||||
let transport = nodemailer.createTransport({
|
|
||||||
host: config.dict.smtpHost,
|
|
||||||
port: config.dict.smtpPort,
|
|
||||||
secure: false,
|
|
||||||
tls: {
|
|
||||||
rejectUnauthorized: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let mail = {
|
|
||||||
from: config.dict.smtpSender,
|
|
||||||
to: config.dict.smtpReceiver,
|
|
||||||
subject: subject,
|
|
||||||
text: message
|
|
||||||
};
|
|
||||||
transport.sendMail(mail)
|
|
||||||
.then((v) => {
|
|
||||||
info(`Mail sent, ${subject}, ${message}, ${v.response}`);
|
|
||||||
})
|
|
||||||
.catch((reason) => {
|
|
||||||
error(`Failure when sending alarm mail: ${message}, ${reason}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.sendAlarmMail = sendAlarmMail;
|
|
||||||
function info(message) {
|
function info(message) {
|
||||||
if (level < Level.NoDebugNoInfo) {
|
if (level < Level.NoDebugNoInfo) {
|
||||||
console.log(`${timestamp()} [ II ] ${message}`);
|
console.log(`${timestamp()} [ II ] ${message}`);
|
||||||
|
2
dist/log.js.map
vendored
2
dist/log.js.map
vendored
@ -1 +1 @@
|
|||||||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O,CAAC,GAAG,CAAC,GAAG,SAAS,EAAE,WAAW,OAAO,EAAE,CAAC,CAAA;KAClD;AACL,CAAC;AAJD,sBAIC"}
|
12
dist/main.js
vendored
12
dist/main.js
vendored
@ -12,11 +12,16 @@ app.engine('pag', (filePath, options, callback) => {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(new Error(err.message));
|
return callback(new Error(err.message));
|
||||||
}
|
}
|
||||||
let renderedPhase1 = content.toString()
|
let contentStr = content.toString();
|
||||||
|
let pageOptionsStr = contentStr.replace(/^\s+<!-- (\{.*\}) -->.*$/, "\$1");
|
||||||
|
logger.info(`contentStr: ${contentStr}`);
|
||||||
|
logger.info(`pageOptionsStr: ${pageOptionsStr}`);
|
||||||
|
let pageOptions = JSON.parse(pageOptionsStr);
|
||||||
|
let renderedPhase1 = contentStr
|
||||||
.replace('#bla#', 'blu');
|
.replace('#bla#', 'blu');
|
||||||
let renderedPhase2 = masterTmpl
|
let renderedPhase2 = masterTmpl
|
||||||
.replace('#maincontent#', renderedPhase1)
|
.replace('#maincontent#', renderedPhase1)
|
||||||
.replace('#title#', options.title);
|
.replace('#title#', pageOptions.title);
|
||||||
return callback(null, renderedPhase2);
|
return callback(null, renderedPhase2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -25,6 +30,9 @@ app.set('view engine', 'pag');
|
|||||||
app.get('/index', (req, res) => {
|
app.get('/index', (req, res) => {
|
||||||
res.render('index', { 'title': 'Projects - just for fun' });
|
res.render('index', { 'title': 'Projects - just for fun' });
|
||||||
});
|
});
|
||||||
|
app.get('/posts/:date', (req, res) => {
|
||||||
|
res.render(`posts/${req.params.date}/article`, {});
|
||||||
|
});
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
res.send('Hello world!');
|
res.send('Hello world!');
|
||||||
});
|
});
|
||||||
|
2
dist/main.js.map
vendored
2
dist/main.js.map
vendored
@ -1 +1 @@
|
|||||||
{"version":3,"file":"main.js","sourceRoot":"","sources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AAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA"}
|
142
docroot/posts/2018-04-30.01/article.pag
Normal file
142
docroot/posts/2018-04-30.01/article.pag
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
<!-- { "title": "Yet Another Debouncing Method" } -->
|
||||||
|
|
||||||
|
You can find several approaches for debouncing mechanical switches on the Internet, some work better, some not so good.
|
||||||
|
|
||||||
|
One common approach is to ignore events in an ISR when they come too fast:
|
||||||
|
|
||||||
|
[code language="C"]
|
||||||
|
void count() {
|
||||||
|
static uint32_t lastEvent = 0;
|
||||||
|
uint32_t currentEvent = micros();
|
||||||
|
if (currentEvent > (lastEvent + configBlock.debounce)) {
|
||||||
|
lastEvent = currentEvent;
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
pinMode(REED_PIN, INPUT_PULLUP);
|
||||||
|
attachInterrupt(REED_PIN, count, FALLING);
|
||||||
|
}
|
||||||
|
[/code]
|
||||||
|
|
||||||
|
This works very good when only the tipping of a switch is relevant.
|
||||||
|
|
||||||
|
When also the time the button was pressed is relevant and when it is especially necessary to distinguish between a short and a long press this approach doesn't work anymore.
|
||||||
|
|
||||||
|
Since I couldn't remember the approaches I read about earlier I've sketched this state machine:
|
||||||
|
|
||||||
|
|
||||||
|
<!--more-->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<img src="https://a385e5.files.wordpress.com/2018/04/20180430110848869_0001.jpg" alt="20180430110848869_0001.jpg" width="2332" height="3307" class="alignnone size-full wp-image-901" />
|
||||||
|
|
||||||
|
(The double-lined states are action-states which send out the related information.)
|
||||||
|
|
||||||
|
At least for me, this approach is working very reliable so far, I'm quite happy with it.
|
||||||
|
|
||||||
|
[code language="C"]
|
||||||
|
enum tPressedState { psHIGH, psLOW, psACCEPTED_LOW, psLONG_START, psLONG_CONT, psLONG_CONT_SEND, psLONG_END, psSHORT, psINVALID };
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t index;
|
||||||
|
uint8_t buttonPin;
|
||||||
|
tPressedState pressedState;
|
||||||
|
tPressedState oldPressedState;
|
||||||
|
uint32_t lastStateChange;
|
||||||
|
} tButton;
|
||||||
|
|
||||||
|
tButton buttons[] = {
|
||||||
|
{ 1, SWITCH_1, psHIGH, psINVALID, 0 },
|
||||||
|
{ 2, SWITCH_2, psHIGH, psINVALID, 0 },
|
||||||
|
{ 3, SWITCH_3, psHIGH, psINVALID, 0 },
|
||||||
|
{ 0, 0, psINVALID, psINVALID, 0 } // END MARKER
|
||||||
|
};
|
||||||
|
|
||||||
|
static void buttonHandler(tButton *button) {
|
||||||
|
uint32_t currentMicros = micros();
|
||||||
|
uint8_t buttonState = digitalRead(button->buttonPin);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (button->oldPressedState != button->pressedState) {
|
||||||
|
Serial.print("Index ");
|
||||||
|
Serial.print(button->index);
|
||||||
|
Serial.print(", state changed from ");
|
||||||
|
Serial.print(button->oldPressedState);
|
||||||
|
Serial.print(" to ");
|
||||||
|
Serial.print(button->pressedState);
|
||||||
|
Serial.println();
|
||||||
|
button->oldPressedState = button->pressedState;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch (button->pressedState) {
|
||||||
|
case psHIGH:
|
||||||
|
if (buttonState == LOW) {
|
||||||
|
button->pressedState = psLOW;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case psLOW:
|
||||||
|
if (buttonState == HIGH) {
|
||||||
|
button->pressedState = psHIGH;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
} else {
|
||||||
|
if (currentMicros > (button->lastStateChange + configBlock.debounce)) {
|
||||||
|
button->pressedState = psACCEPTED_LOW;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case psACCEPTED_LOW:
|
||||||
|
if (buttonState == HIGH) {
|
||||||
|
button->pressedState = psSHORT;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
}
|
||||||
|
if (currentMicros > (button->lastStateChange + (configBlock.longPress * 1000))) {
|
||||||
|
button->pressedState = psLONG_START;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case psSHORT:
|
||||||
|
sendMsg(button->index, "PRESS_SHORT");
|
||||||
|
button->pressedState = psHIGH;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
break;
|
||||||
|
case psLONG_START:
|
||||||
|
sendMsg(button->index, "PRESS_LONG_START");
|
||||||
|
button->pressedState = psLONG_CONT;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
break;
|
||||||
|
case psLONG_CONT:
|
||||||
|
if (buttonState == HIGH) {
|
||||||
|
button->pressedState = psLONG_END;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
}
|
||||||
|
if (currentMicros > (button->lastStateChange + (configBlock.longPressRepeat * 1000))) {
|
||||||
|
button->pressedState = psLONG_CONT_SEND;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case psLONG_CONT_SEND:
|
||||||
|
sendMsg(button->index, "PRESS_LONG_CONT");
|
||||||
|
button->pressedState = psLONG_CONT;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
break;
|
||||||
|
case psLONG_END:
|
||||||
|
sendMsg(button->index, "PRESS_LONG_END");
|
||||||
|
button->pressedState = psHIGH;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
button->pressedState = psHIGH;
|
||||||
|
button->lastStateChange = currentMicros;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[/code]
|
||||||
|
|
||||||
|
Find it embedded in the code of a small ESP8266-based switch thing I'm using in my home automation setup (home grown control code (https://gitlab.com/wolutator/dispatcher_ng), homegear (https://homegear.eu/) for device integration and openHAB (https://www.openhab.org/) as user interface) here: https://gitlab.com/wolutator/MySwitch.
|
||||||
|
|
||||||
|
')
|
16
node_modules/.bin/mime
generated
vendored
16
node_modules/.bin/mime
generated
vendored
@ -1 +1,15 @@
|
|||||||
../mime/cli.js
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
"$basedir/node" "$basedir/../mime/cli.js" "$@"
|
||||||
|
ret=$?
|
||||||
|
else
|
||||||
|
node "$basedir/../mime/cli.js" "$@"
|
||||||
|
ret=$?
|
||||||
|
fi
|
||||||
|
exit $ret
|
||||||
|
7
node_modules/.bin/mime.cmd
generated
vendored
Normal file
7
node_modules/.bin/mime.cmd
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
@IF EXIST "%~dp0\node.exe" (
|
||||||
|
"%~dp0\node.exe" "%~dp0\..\mime\cli.js" %*
|
||||||
|
) ELSE (
|
||||||
|
@SETLOCAL
|
||||||
|
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||||
|
node "%~dp0\..\mime\cli.js" %*
|
||||||
|
)
|
45
npm-debug.log
Normal file
45
npm-debug.log
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
0 info it worked if it ends with ok
|
||||||
|
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
|
||||||
|
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
|
||||||
|
1 verbose cli 'start',
|
||||||
|
1 verbose cli '--',
|
||||||
|
1 verbose cli '-c',
|
||||||
|
1 verbose cli './homepage.conf' ]
|
||||||
|
2 info using npm@2.15.9
|
||||||
|
3 info using node@v4.5.0
|
||||||
|
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
|
||||||
|
5 info prestart homepage@1.0.0
|
||||||
|
6 info start homepage@1.0.0
|
||||||
|
7 verbose unsafe-perm in lifecycle true
|
||||||
|
8 info homepage@1.0.0 Failed to exec start script
|
||||||
|
9 verbose stack Error: homepage@1.0.0 start: `node dist/main.js "-c" "./homepage.conf"`
|
||||||
|
9 verbose stack Exit status 1
|
||||||
|
9 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:217:16)
|
||||||
|
9 verbose stack at emitTwo (events.js:87:13)
|
||||||
|
9 verbose stack at EventEmitter.emit (events.js:172:7)
|
||||||
|
9 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14)
|
||||||
|
9 verbose stack at emitTwo (events.js:87:13)
|
||||||
|
9 verbose stack at ChildProcess.emit (events.js:172:7)
|
||||||
|
9 verbose stack at maybeClose (internal/child_process.js:829:16)
|
||||||
|
9 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
|
||||||
|
10 verbose pkgid homepage@1.0.0
|
||||||
|
11 verbose cwd C:\Users\dehottgw\workspaces\workspace-private\homepage
|
||||||
|
12 error Windows_NT 6.1.7601
|
||||||
|
13 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" "--" "-c" "./homepage.conf"
|
||||||
|
14 error node v4.5.0
|
||||||
|
15 error npm v2.15.9
|
||||||
|
16 error code ELIFECYCLE
|
||||||
|
17 error homepage@1.0.0 start: `node dist/main.js "-c" "./homepage.conf"`
|
||||||
|
17 error Exit status 1
|
||||||
|
18 error Failed at the homepage@1.0.0 start script 'node dist/main.js "-c" "./homepage.conf"'.
|
||||||
|
18 error This is most likely a problem with the homepage package,
|
||||||
|
18 error not with npm itself.
|
||||||
|
18 error Tell the author that this fails on your system:
|
||||||
|
18 error node dist/main.js "-c" "./homepage.conf"
|
||||||
|
18 error You can get information on how to open an issue for this project with:
|
||||||
|
18 error npm bugs homepage
|
||||||
|
18 error Or if that isn't available, you can get their info via:
|
||||||
|
18 error
|
||||||
|
18 error npm owner ls homepage
|
||||||
|
18 error There is likely additional logging output above.
|
||||||
|
19 verbose exit [ 1, true ]
|
@ -22,7 +22,6 @@
|
|||||||
"chalk": "^2.3.0",
|
"chalk": "^2.3.0",
|
||||||
"command-line-args": "^4.0.7",
|
"command-line-args": "^4.0.7",
|
||||||
"express": "^4.16.3",
|
"express": "^4.16.3",
|
||||||
"nodemailer": "^4.6.4",
|
|
||||||
"simple-node-logger": "^0.93.33"
|
"simple-node-logger": "^0.93.33"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -30,7 +29,6 @@
|
|||||||
"@types/command-line-args": "^4.0.2",
|
"@types/command-line-args": "^4.0.2",
|
||||||
"@types/express": "^4.11.1",
|
"@types/express": "^4.11.1",
|
||||||
"@types/node": "^8.5.8",
|
"@types/node": "^8.5.8",
|
||||||
"@types/nodemailer": "^4.6.0",
|
|
||||||
"typescript": "^2.6.2"
|
"typescript": "^2.6.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
src/log.ts
27
src/log.ts
@ -1,6 +1,5 @@
|
|||||||
import * as moment from 'moment'
|
import * as moment from 'moment'
|
||||||
import * as config from './config'
|
import * as config from './config'
|
||||||
import * as nodemailer from 'nodemailer'
|
|
||||||
|
|
||||||
|
|
||||||
enum Level {
|
enum Level {
|
||||||
@ -25,32 +24,6 @@ export function setLevel(value: string): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendAlarmMail(subject : string, message : string): void {
|
|
||||||
let transport = nodemailer.createTransport({
|
|
||||||
host: config.dict.smtpHost,
|
|
||||||
port: config.dict.smtpPort,
|
|
||||||
secure: false,
|
|
||||||
tls: {
|
|
||||||
rejectUnauthorized: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let mail : nodemailer.SendMailOptions = {
|
|
||||||
from: config.dict.smtpSender,
|
|
||||||
to: config.dict.smtpReceiver,
|
|
||||||
subject: subject,
|
|
||||||
text: message
|
|
||||||
};
|
|
||||||
|
|
||||||
transport.sendMail(mail)
|
|
||||||
.then((v : nodemailer.SentMessageInfo) => {
|
|
||||||
info(`Mail sent, ${subject}, ${message}, ${v.response}`)
|
|
||||||
})
|
|
||||||
.catch((reason : any) => {
|
|
||||||
error(`Failure when sending alarm mail: ${message}, ${reason}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export function info(message: string): void {
|
export function info(message: string): void {
|
||||||
if (level < Level.NoDebugNoInfo) {
|
if (level < Level.NoDebugNoInfo) {
|
||||||
|
15
src/main.ts
15
src/main.ts
@ -18,12 +18,19 @@ app.engine('pag', (filePath: string, options: any, callback: any) => {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(new Error(err.message))
|
return callback(new Error(err.message))
|
||||||
}
|
}
|
||||||
let renderedPhase1 = content.toString()
|
|
||||||
|
let contentStr = content.toString()
|
||||||
|
let pageOptionsStr = contentStr.replace(/^\s+<!-- (\{.*\}) -->.*$/, "\$1")
|
||||||
|
logger.info(`contentStr: ${contentStr}`)
|
||||||
|
logger.info(`pageOptionsStr: ${pageOptionsStr}`)
|
||||||
|
let pageOptions = JSON.parse(pageOptionsStr)
|
||||||
|
let renderedPhase1 = contentStr
|
||||||
.replace('#bla#', 'blu')
|
.replace('#bla#', 'blu')
|
||||||
|
|
||||||
let renderedPhase2 = masterTmpl
|
let renderedPhase2 = masterTmpl
|
||||||
.replace('#maincontent#', renderedPhase1)
|
.replace('#maincontent#', renderedPhase1)
|
||||||
.replace('#title#', options.title)
|
.replace('#title#', pageOptions.title)
|
||||||
|
|
||||||
return callback(null, renderedPhase2)
|
return callback(null, renderedPhase2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -35,6 +42,10 @@ app.get('/index', (req, res) => {
|
|||||||
res.render('index', {'title': 'Projects - just for fun'})
|
res.render('index', {'title': 'Projects - just for fun'})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.get('/posts/:date', (req, res) => {
|
||||||
|
res.render(`posts/${req.params.date}/article`, {})
|
||||||
|
})
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
res.send('Hello world!')
|
res.send('Hello world!')
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user