Compare commits
No commits in common. "develop" and "master" have entirely different histories.
@ -33,9 +33,6 @@ class PrinterDevice extends EventEmitter {
|
||||
if (chkSerial) {
|
||||
this._device = new escpos.Serial(this._serial)
|
||||
this._type = 'serial'
|
||||
this._device.on('disconnect', () => {
|
||||
self.emit('close')
|
||||
})
|
||||
} else {
|
||||
this._device = new escpos.Console()
|
||||
this._type = 'console'
|
||||
|
34
server.js
34
server.js
@ -66,10 +66,9 @@ if (setupMode) {
|
||||
Printer.feed = config.printer.feed
|
||||
await Printer.connect()
|
||||
|
||||
Printer.on('close', ()=>{
|
||||
console.log('device disconnect')
|
||||
})
|
||||
|
||||
if (config.ble.enable) {
|
||||
require('./ble')
|
||||
}
|
||||
}
|
||||
|
||||
if (router !== null) {
|
||||
@ -92,6 +91,12 @@ localEvent.on('print', async str => {
|
||||
})
|
||||
|
||||
let systemStatus = {
|
||||
ble: {
|
||||
enable: false,
|
||||
mac: '',
|
||||
service: '',
|
||||
characteristic: ''
|
||||
},
|
||||
printer: {
|
||||
connect: false,
|
||||
serial: '',
|
||||
@ -102,8 +107,13 @@ let systemStatus = {
|
||||
secret: ''
|
||||
}
|
||||
|
||||
systemStatus.ble.enable = config.ble.enable
|
||||
systemStatus.secret = config.api.secret
|
||||
|
||||
if (config.ble.enable) {
|
||||
systemStatus.ble.mac = await getBTAddr()
|
||||
systemStatus.ble.service = config.ble.uuid.service
|
||||
systemStatus.ble.characteristic = config.ble.uuid.characteristic
|
||||
}
|
||||
function getPrinterStatus() {
|
||||
systemStatus.printer.connect = Printer.isOpen
|
||||
systemStatus.printer.serial = Printer.serial
|
||||
@ -138,3 +148,17 @@ ws.on('connection', async (client, req) => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
async function getBTAddr() {
|
||||
let address = await new Promise((resolve, reject) => {
|
||||
exec('bt-adapter -i | grep -i address', (err, sout, serr) => {
|
||||
if (err) return resolve('')
|
||||
resolve(sout)
|
||||
})
|
||||
})
|
||||
|
||||
address = address.trim()
|
||||
let arr = address.split(' ')
|
||||
if (arr.length !== 2) return ''
|
||||
return arr[1].trim()
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
<%- include ../includes/header.ejs %>
|
||||
<div class="ui dimmer" id="loader">
|
||||
<div class="ui loader text">Rebooting...</div>
|
||||
</div>
|
||||
|
||||
<div class="ui container" style="padding-top: 20px;">
|
||||
<div class="ui grid">
|
||||
<div class="row">
|
||||
|
@ -40,6 +40,9 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="ui dimmer" id="loader">
|
||||
<div class="ui loader text">Rebooting...</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function getValue(obj){
|
||||
|
@ -3,7 +3,7 @@
|
||||
<div class="column sixteen wide t-right">
|
||||
<div class="ui segment">
|
||||
<button class="ui button mini" type="button" id="gen-api-qr">Generate API QR</button>
|
||||
<button class="ui button mini red" type="button" id="dev-reboot">Reboot</button>
|
||||
<button class="ui button mini" type="button" id="gen-ble-qr">Generate BLE QR</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column sixteen wide">
|
||||
@ -19,21 +19,45 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column eight wide">
|
||||
<div class="segment ui">
|
||||
<h4 class="ui header dividing">藍芽狀態</h4>
|
||||
<div class="ui divided list">
|
||||
<div class="item">
|
||||
<div class="ui horizontal label basic">啟用狀態</div>
|
||||
<div class="description t-right" id="en-ble">On</div>
|
||||
</div>
|
||||
<div class="item">
|
||||
<div class="ui horizontal label basic">Mac Address</div>
|
||||
<div class="description t-right" id="ble-mac">00:11:22:33:44:55:66</div>
|
||||
</div>
|
||||
<div class="item">
|
||||
<div class="ui horizontal label basic">ServiceUUID</div>
|
||||
<div class="description t-right" id="ble-service">37B2975E-1A4B-4975-9211-9D47142B8183</div>
|
||||
</div>
|
||||
<div class="item">
|
||||
<div class="ui horizontal label basic">CharacteristicUUID</div>
|
||||
<div class="description t-right" id="ble-character">37B2975E-1A4B-4975-9211-9D47142B8183</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column eight wide">
|
||||
<div class="segment ui">
|
||||
<h4 class="ui header dividing">印表機狀態</h4>
|
||||
<div class="ui divided list">
|
||||
<div class="item">
|
||||
<div class="ui horizontal label basic">連線狀態</div>
|
||||
<div class="description t-right" id="prt-con"></div>
|
||||
<div class="description t-right" id="prt-con">Disconnected</div>
|
||||
</div>
|
||||
<div class="item">
|
||||
<div class="ui horizontal label basic">連接埠</div>
|
||||
<div class="description t-right" id="prt-port"></div>
|
||||
<div class="description t-right" id="prt-port">/dev/ttyUSB0</div>
|
||||
</div>
|
||||
<div class="item">
|
||||
<div class="ui horizontal label basic">切紙前空行</div>
|
||||
<div class="description t-right" id="prt-feed"></div>
|
||||
<div class="description t-right" id="prt-feed">8</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -66,20 +90,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ui mini modal" id="confirm-box">
|
||||
<div class=" content">
|
||||
確定要把設備重新啟動嗎?
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui black deny button" id="close">
|
||||
取消
|
||||
</div>
|
||||
<div class="ui button red" id="run">
|
||||
確定
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var setting = {
|
||||
mac: '',
|
||||
@ -88,17 +98,8 @@
|
||||
}
|
||||
|
||||
var apikey = ''
|
||||
var ws = null
|
||||
|
||||
function connectSocket() {
|
||||
ws = new WebSocket('ws://' + location.host)
|
||||
ws.onclose = () => {
|
||||
ws = null
|
||||
setTimeout(() => {
|
||||
console.log(`try reconnect`)
|
||||
connectSocket()
|
||||
}, 2000)
|
||||
}
|
||||
var ws = new WebSocket('ws://' + location.host)
|
||||
ws.onmessage = msg => {
|
||||
// console.log(msg)
|
||||
let data = {}
|
||||
@ -112,6 +113,14 @@
|
||||
case 'status':
|
||||
console.log(data)
|
||||
let d = data.data
|
||||
$('#en-ble').text(d.ble.enable ? 'On' : 'Off')
|
||||
$('#ble-mac').text(d.ble.mac)
|
||||
$('#ble-service').text(d.ble.service)
|
||||
$('#ble-character').text(d.ble.characteristic)
|
||||
|
||||
setting.mac = d.ble.mac
|
||||
setting.service = d.ble.service
|
||||
setting.characteristic = d.ble.characteristic
|
||||
|
||||
apikey = d.secret
|
||||
$('#apikey').text(apikey)
|
||||
@ -126,43 +135,18 @@
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connectSocket()
|
||||
|
||||
$('#gen-api-qr').click(function () {
|
||||
$('#gen-ble-qr, #gen-api-qr').click(function () {
|
||||
let qrdiv = document.querySelector('div#qr')
|
||||
qrdiv.innerHTML = ''
|
||||
let qr = new QRCode(qrdiv, {
|
||||
text: JSON.stringify({ apikey }, null, 2),
|
||||
text: this.id === 'gen-ble-qr' ? JSON.stringify(setting, null, 2) : JSON.stringify({apikey}, null, 2),
|
||||
colorDark: "#000000",
|
||||
colorLight: "#ffffff",
|
||||
correctLevel: QRCode.CorrectLevel.L
|
||||
})
|
||||
// qr.makeCode(JSON.stringify(setting, null, 2))
|
||||
$('#qr-dimmer').dimmer('show')
|
||||
})
|
||||
|
||||
$('#dev-reboot').click(function(){
|
||||
$('#confirm-box').modal('show')
|
||||
$('#confirm-box #close').unbind('click').click(function(){
|
||||
$('#confirm-box').modal('hide')
|
||||
})
|
||||
$('#confirm-box #run').unbind('click').click(function(){
|
||||
$('#confirm-box').modal('hide')
|
||||
$.ajax({
|
||||
url: '/reboot_sys',
|
||||
type: 'put',
|
||||
success: function(){
|
||||
setTimeout(function(){
|
||||
location.replace('/')
|
||||
}, 30000)
|
||||
$('#loader').addClass('active')
|
||||
},
|
||||
error: function(){
|
||||
alert('系統重新啟動失敗')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user