Skip to content

Commit

Permalink
save log file
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanSST committed Mar 19, 2024
1 parent 50ca8b2 commit f67a050
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ buildNumber.properties
.mvn
/logs/
/RasPiProducer-tcphuehnerstall1883/
/EclipseProducer-tcphuehnerstall1883/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ This code will run on a Raspberry PI in a chicken barn. There are scales under t
### Epic v1: Chicken scale recognizes weight change and sends message about state (which chicken, an egg) via Messenger

* check logs; observer and service log twice
* log messures to file or Prometheus
* implement calibrate
* write tests and mocks for mqtt client
* correct shutdown of mqtt user


## TODO List Arduino
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/ch/stephan/chickenfarm/mqtt/MqttConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

@Slf4j
@RequiredArgsConstructor
@Profile("default")
@Profile({ "default", "dev" })
@Configuration
public class MqttConfig {

private static final String MQTT_CLIENT_ID = "RasPiConsumer";
@Value("${mqtt.clientId.consumer}")
private String mqttClientId;

@Autowired
private BoxService boxService;
Expand Down Expand Up @@ -55,7 +56,7 @@ MqttPahoClientFactory mqttClientFactory() {

@Bean
MessageProducer inbound() {
MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(MQTT_CLIENT_ID,
MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(mqttClientId,
mqttClientFactory(), "/chicken-farm/replies");

adapter.setCompletionTimeout(5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Profile("default")
@Profile({ "default", "dev" })
@Configuration
public class MqttConfiguration {

private static final String MQTT_CLIENT_ID = "RasPiProducer";
@Value("${mqtt.clientId.producer}")
private String mqttClientId;

@Value("${mqtt.user}")
private String user;
Expand All @@ -34,7 +35,7 @@ IMqttClient mqttClient() throws MqttException {
options.setCleanSession(true);
options.setConnectionTimeout(10);

IMqttClient mqttClient = new MqttClient("tcp://huehnerstall:1883", MQTT_CLIENT_ID);
IMqttClient mqttClient = new MqttClient("tcp://huehnerstall:1883", mqttClientId);
mqttClient.connect(options);
log.info("successfully connected to MQTT server");
return mqttClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
{
"properties": [
{
"name": "messengerservice.enabled",
"type": "java.lang.String",
"description": "Send messages by messenger or not."
},
{
"name": "messengerservice.channel",
"type": "java.lang.String",
"description": "Name of the Slack channel to publish the messages"
},
{
"name": "messengerservice.token",
"type": "java.lang.String",
"description": "The security token to use Slack"
},
{
"name": "schedulerservice.observer.cron",
"type": "java.lang.String",
"description": "Cron expression for scale observer"
},
{
"name": "schedulerservice.tare.cron",
"type": "java.lang.String",
"description": "Cron expression when to tare the scale"
},
{
"name": "mqtt.user",
"type": "java.lang.String",
"description": "User id of the mqtt service"
},
{
"name": "mqtt.password",
"type": "java.lang.String",
"description": "Password of the mqtt service"
}
]
}
{"properties": [
{
"name": "messengerservice.enabled",
"type": "java.lang.String",
"description": "Send messages by messenger or not."
},
{
"name": "messengerservice.channel",
"type": "java.lang.String",
"description": "Name of the Slack channel to publish the messages"
},
{
"name": "messengerservice.token",
"type": "java.lang.String",
"description": "The security token to use Slack"
},
{
"name": "schedulerservice.observer.cron",
"type": "java.lang.String",
"description": "Cron expression for scale observer"
},
{
"name": "schedulerservice.tare.cron",
"type": "java.lang.String",
"description": "Cron expression when to tare the scale"
},
{
"name": "mqtt.user",
"type": "java.lang.String",
"description": "User id of the mqtt service"
},
{
"name": "mqtt.password",
"type": "java.lang.String",
"description": "Password of the mqtt service"
},
{
"name": "mqtt.clientId.producer",
"type": "java.lang.String",
"description": "Client id of the producer of mqtt events"
},
{
"name": "mqtt.clientId.consumer",
"type": "java.lang.String",
"description": "Client id of the consumer of mqtt events"
}
]}
5 changes: 4 additions & 1 deletion src/main/resources/application-maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ schedulerservice:

mqtt:
user: dummy
password: dummy
password: dummy
clientId:
producer: MavenProducer
consumer: MavenConsumer
12 changes: 11 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ schedulerservice:

mqtt:
user: ${MQTT_USER}
password: ${MQTT_PASSWORD}
password: ${MQTT_PASSWORD}
clientId:
producer: RasPiProducer
consumer: RasPiConsumer

logging:
file:
name: /logs/application-debug.log
logback:
rollingpolicy:
max-history: 14
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@RequiredArgsConstructor
@Configuration
@Profile({ "maven", "dev" })
@Profile("maven")
public class MockedMqttConfig {

@MockBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile({ "maven", "dev" })
@Profile("maven")
@Configuration
public class MockedMqttConfiguration {

Expand Down

0 comments on commit f67a050

Please sign in to comment.