在昨天我们把资料写入了firebase,接下来我们再利用googleHomeTrigger 藉由onUpdate进行传递讯息
exports.googleHomeTrigger = functions.firestore.document('personal-accounts/{firebaseId}/peoples/{tagMac}')
.onUpdate(async (change, context) => {
const beforeData = change.before.data() as peopleInterface
const afterData = change.after.data() as peopleInterface
// const firebaseId = context.params.firebaseId
// const tagMac = context.params.tagMac
const physiologicalState = verifyPhysiologicalState(beforeData, afterData)
// const moudule = getLocation(afterData)
await notifyPhysiological(physiologicalState, afterData)
.catch(err =>console.log(err))
});
接着新增:
beforeCoachMessage
afterCoachMessage
(因并非与其他生理状态写在同一个map里)
当coachMessage update 让physiologicalState = 8
const verifyPhysiologicalState = (beforeData: peopleInterface, afterData: peopleInterface): number => {
let physiologicalState
const beforePhysiological = beforeData.physiological
const afterPhysiological = afterData.physiological
const beforeCoachMessage = beforeData.coachMessage
const afterCoachMessage = afterData.coachMessage
if (afterPhysiological.HR != beforePhysiological.HR) {
//心律
if(afterPhysiological.HR >= 90 || afterPhysiological.HR <= 60){
physiologicalState = 1
}
}
.
.
.
else if (beforeData.coachMessage != afterData.coachMessage) {
physiologicalState = 8
} else {
//生理数据不变
physiologicalState = 0
}
return physiologicalState
}
再新增switch case=>当physiological state=8时,产生如下的message
case 8:
// notifyMessage = `${afterData.name}血糖为${afterData.physiological?.BS}`
notifyMessage = {
tagMAC:afterData.tagMAC,
name:afterData.name,
result:`${afterData.coachMessage}`,
message:`${afterData.coachMessage}`,
moudule:arr[0]
}
break;
即可完成传送coach message
>>: [30] 30 天从 Swift 学会 Objective-C:30 天内那些我不懂的部分
你是否曾经好奇浏览网页时,输入的网址为什麽都是 http 开头的? 从网路模型 TCP/IP 聊起,...
EQUAL & NOT EQUA 如同字面上意思,筛选出指定相符的资料,可以以=来表示。 而...
昨天提到如何使用 kotlinx.serialization 处理 request/response...
结语 感谢铁人赛的契机,让我又完成一门课了,虽然是一门基础的课程,但是过程中依然放了不少心力,看那几...
● 这章来示范如何取得指数(Indexs)的ticks 回顾上一章,我们学会如何取得选择权的tick...