Warning: Declaration of action_plugin_indexmenu::register(&$controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /home/httpd/vhosts/scratchbook.ch/wiki.scratchbook.ch/lib/plugins/indexmenu/action.php on line 18 Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/scratchbook.ch/wiki.scratchbook.ch/lib/plugins/indexmenu/action.php:0) in /home/httpd/vhosts/scratchbook.ch/wiki.scratchbook.ch/inc/auth.php on line 495 Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/scratchbook.ch/wiki.scratchbook.ch/lib/plugins/indexmenu/action.php:0) in /home/httpd/vhosts/scratchbook.ch/wiki.scratchbook.ch/inc/actions.php on line 210
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
sfera:serialport [2016/12/05 14:18] claude |
sfera:serialport [2016/12/08 12:06] (current) claude [Suddenly, it works] |
||
---|---|---|---|
Line 53: | Line 53: | ||
</code> | </code> | ||
+ | I'm connecting using the same parameters as the decoder in the logic analyzer; baudrate 19200, databits 8, stopbits 1, parity none. | ||
+ | |||
+ | The manual of the weather station says that we should receive exactly 40 bytes, but when I read 40 bytes with Node.js, the whole streamblock gets shifted. I need to read 42 bytes, sometimes 43 bytes. | ||
===== Horizontally represented: ===== | ===== Horizontally represented: ===== | ||
Line 62: | Line 65: | ||
<code> | <code> | ||
- | 57 2B 31 39 2E 36... | + | 57 2B 31 39 2E 36 ... |
</code> | </code> | ||
- | 0x57: W (start bit weather-data) | + | 57: W (start bit weather-data)\\ |
2B 31 39 2E 36: +19.6° (temperature) | 2B 31 39 2E 36: +19.6° (temperature) | ||
Line 71: | Line 74: | ||
{{:sfera:weather-station.png?nolink|}} | {{:sfera:weather-station.png?nolink|}} | ||
+ | |||
+ | ===== Suddenly, it works ===== | ||
+ | |||
+ | <code> | ||
+ | root@raspberrypi:~/dali# coffee wetter.coffee 40 | ||
+ | undefined | ||
+ | <Buffer 57 2b 32 34 2e 34 30 30 30 30 30 30 4e 34 39 39 30 31 2e 32 4e 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 32 30 31 35 03> | ||
+ | <Buffer 57 2b 32 34 2e 34 30 30 30 30 30 30 4e 34 39 38 30 31 2e 32 4e 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 32 30 31 34 03> | ||
+ | <Buffer 57 2b 32 34 2e 34 30 30 30 30 30 30 4e 34 39 38 30 31 2e 32 4e 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 32 30 31 34 03> | ||
+ | <Buffer 57 2b 32 34 2e 34 30 30 30 30 30 30 4e 34 39 37 30 31 2e 32 4e 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 32 30 31 33 03> | ||
+ | <Buffer 57 2b 32 34 2e 34 30 30 30 30 30 30 4e 34 39 37 30 31 2e 32 4e 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 32 30 31 33 03> | ||
+ | ^ | ||
+ | |||
+ | <Buffer 57 2b 32 35 2e 31 30 30 30 30 30 30 4e 35 36 35 30 30 2e 35 4e 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 32 30 30 39 03> | ||
+ | 1: W | ||
+ | 2: + | ||
+ | 3: 2 | ||
+ | 4: 5 | ||
+ | 5: . | ||
+ | 6: 1 | ||
+ | 7: 0 | ||
+ | 8: 0 | ||
+ | 9: 0 | ||
+ | 10: 0 | ||
+ | 11: 0 | ||
+ | 12: 0 | ||
+ | 13: N | ||
+ | 14: 5 | ||
+ | 15: 6 | ||
+ | 16: 5 | ||
+ | 17: 0 | ||
+ | 18: 0 | ||
+ | 19: . | ||
+ | 20: 5 | ||
+ | 21: N | ||
+ | 22: ? | ||
+ | 23: ? | ||
+ | 24: ? | ||
+ | 25: ? | ||
+ | 26: ? | ||
+ | 27: ? | ||
+ | 28: ? | ||
+ | 29: ? | ||
+ | 30: ? | ||
+ | 31: ? | ||
+ | 32: ? | ||
+ | 33: ? | ||
+ | 34: ? | ||
+ | 35: ? | ||
+ | 36: 2 | ||
+ | 37: 0 | ||
+ | 38: 0 | ||
+ | 39: 9 | ||
+ | 40: | ||
+ | </code> | ||
+ | |||
+ | <code> | ||
+ | SerialPort = require 'serialport' | ||
+ | |||
+ | port = new SerialPort "/dev/ttyAMA0", | ||
+ | baudRate: 19200 | ||
+ | dataBits: 8 | ||
+ | stopBits: 1 | ||
+ | parity: 'none' | ||
+ | rtscts: true | ||
+ | xon: true | ||
+ | xoff: true | ||
+ | xany: true | ||
+ | #parser: SerialPort.parsers.readline 0xf9 | ||
+ | parser: SerialPort.parsers.byteLength process.argv[2] | ||
+ | #parser: SerialPort.parsers.raw | ||
+ | #parser: SerialPort.parsers.byteDelimiter [0xf9] | ||
+ | |||
+ | port.on 'open', (data) -> | ||
+ | console.info data | ||
+ | |||
+ | port.on 'error', (data) -> | ||
+ | console.info "error: ", data | ||
+ | |||
+ | port.on 'data', (data) -> | ||
+ | console.info data | ||
+ | i = 1 | ||
+ | for d in data | ||
+ | console.info "#{i}: #{hex2ascii(d)}" | ||
+ | i++ | ||
+ | |||
+ | dec2bin = (dec) -> | ||
+ | (dec >>> 0).toString(2) | ||
+ | |||
+ | hex2ascii = (hex) -> | ||
+ | String.fromCharCode hex | ||
+ | |||
+ | </code> |