Skip to content

Commit

Permalink
disable messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanSST committed Sep 17, 2023
1 parent 58d5727 commit b0ba65b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

## Summary

This code will run on a Raspberry PI in a chicken barn. There are scales under the laying boxes that detect weight changes and computes the event (like chicken in, chicken-out-left-egg etc). These events will be sent by Whatsapp.
This code will run on a Raspberry PI in a chicken barn. There are scales under the laying boxes that detect weight changes and computes the event (like chicken in, chicken-out-left-egg etc). These events will be sent by Messenger.

## TODO List

### Epic v1: Chicken scale recognizes weight change and sends message about state (which chicken, an egg) via Whatsapp
### Epic v1: Chicken scale recognizes weight change and sends message about state (which chicken, an egg) via Messenger

* Story: get current weight and calculate the "state" (chicken, egg)

* Story: using Lombok to log
* Story: write tests and mock for scale service (testing)
* Story: Integration test with whole process (testing)
* Story: using Lombok to log

* Story: (done) get current weight and calculate the "state" (chicken, egg)
* Story: (done) env values via application.yaml
* Story: (done) integrate Threema and send messages
* Story: (done) read data from scale and show by webservice (GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ public class MessengerService {
@Value("${messengerservice.secret}")
private String secret;

@Value("${messengerservice.enabled:false}")
private boolean enabled;

public MessengerService(RestTemplateBuilder restTemplateBuilder) {
this.restTemplate = restTemplateBuilder.build();
}

public String sendNotification(String message) {
if (!enabled) {
return "Messaging was disabled, not message sent.";
}

try {
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/ch/stephan/chickenfarm/timer/ScaleObserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ScaleObserver {
private ScaleService scaleService;

@Autowired
private MessengerService whatsappService;
private MessengerService messengerService;

// @Scheduled(fixedRate = 10000)
public void measureWeights() {
Expand All @@ -34,13 +34,15 @@ public void measureWeights() {
String message = MessageFormatter
.format("Ein Huhn sitzt in der Legebox {} und ist {}g schwer.", uid, weight).getMessage();
log.info(message);
whatsappService.sendNotification(message);
String result = messengerService.sendNotification(message);
log.info("Message sent: {}", result);

} else if (weight > 50) { // egg in the box
String message = MessageFormatter.format("Huhn in der Legebox {} hat ein Ei von {}g gelegt.", uid, weight)
.getMessage();
log.info(message);
whatsappService.sendNotification(message);
String result = messengerService.sendNotification(message);
log.info("Message sent: {}", result);

} else { // nothing special
log.info("Box {} with weight {}g at {}", uid, weight, dateFormat.format(new Date()));
Expand Down

0 comments on commit b0ba65b

Please sign in to comment.