Skip to content

Instantly share code, notes, and snippets.

@nippe
Created May 11, 2016 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nippe/cb52fdddb26cc355dbb9c7db0a69266b to your computer and use it in GitHub Desktop.
Save nippe/cb52fdddb26cc355dbb9c7db0a69266b to your computer and use it in GitHub Desktop.
void loop() {
getWaterLevel();
checkWaterLevel();
delay(DELAY_IN_SECONDS * 1000);
}
int getWaterLevel() {
waterLevel = analogRead(waterLevelPin);
return waterLevel;
}
int sendSms(String command) {
if(command.length() > 0){
Particle.publish("twilio", command, 60, PRIVATE);
}
return 0;
}
void checkWaterLevel() {
int currentLevel = analogRead(waterLevelPin);
if(currentLevel > waterThreshold) {
if(!isMessageSent){
char msg[255];
snprintf(msg, sizeof(msg), "Dags att tömma vatten i källarn! Nivå: %d", waterLevel);
sendSms(msg);
isMessageSent = true;
}
}
if(isMessageSent && (currentLevel < waterThreshold)) {
isMessageSent = false;
sendSms("Du har tömt ser jag, lysande polarn!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment