Last active
March 20, 2022 07:45
-
-
Save jan-osch/fccc769b0aab89ada77a3b808fb193e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Micro-app Code | |
io.press(() => { | |
print('sending alert'); | |
cloud.enqueue('alert', {}); | |
sync.now(); | |
}); | |
function turnOnLED(){ | |
io.led(true); | |
timers.single(3000, () => { | |
io.led(false); | |
}); | |
} | |
sensors.accel.onMotion((inMotion) => { | |
if(inMotion){ | |
turnOnLED(); | |
print('the beacon has been moved') | |
} | |
}) | |
// Cloud Code | |
const accountSid = 'PASTE_YOUR_TWILIO_ACCOUNT_SID_HERE'; | |
const authToken = 'PASTE_YOUR_TWILIO_AUTH_TOKEN_HERE'; | |
module.exports = async function (event) { | |
if (event.type === 'alert') { | |
if (accountSid === 'PASTE_YOUR_TWILIO_ACCOUNT_SID_HERE') { | |
console.log('Twilio is not set up, not sending an SMS'); | |
} else { | |
const twilio = require('twilio')(accountSid, authToken); | |
await twilio.messages.create({ | |
body: 'Alert notification', | |
to: 'PASTE_YOUR_PHONE_NUMBER_HERE', | |
from: 'PASTE_YOUR_TWILIO_VERIFIED_NUMBER_HERE', | |
}); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment