Add camel config #1
5 changed files with 275 additions and 74 deletions
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#Maven
|
||||||
|
target/
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
release.properties
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Eclipse
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.settings/
|
||||||
|
bin/
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
.idea
|
||||||
|
*.ipr
|
||||||
|
*.iml
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# NetBeans
|
||||||
|
nb-configuration.xml
|
||||||
|
|
||||||
|
# Visual Studio Code
|
||||||
|
.vscode
|
||||||
|
.factorypath
|
||||||
|
|
||||||
|
# OSX
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Vim
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# patch
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
|
|
||||||
|
# Local environment
|
||||||
|
.env
|
||||||
110
README.md
110
README.md
|
|
@ -1,92 +1,54 @@
|
||||||
# teslamate-mqtt2telegram
|
# teslamate-mqtt2telegram Project
|
||||||
|
|
||||||
|
This project uses Quarkus, the Supersonic Subatomic Java Framework.
|
||||||
|
|
||||||
|
If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .
|
||||||
|
|
||||||
## Getting started
|
## Running the application in dev mode
|
||||||
|
|
||||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
You can run your application in dev mode that enables live coding using:
|
||||||
|
```shell script
|
||||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
./mvnw compile quarkus:dev
|
||||||
|
|
||||||
## Add your files
|
|
||||||
|
|
||||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
||||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
|
||||||
|
|
||||||
```
|
|
||||||
cd existing_repo
|
|
||||||
git remote add origin http://gitlab/c4181/teslamate-mqtt2telegram.git
|
|
||||||
git branch -M main
|
|
||||||
git push -uf origin main
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Integrate with your tools
|
> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
|
||||||
|
|
||||||
- [ ] [Set up project integrations](http://gitlab/c4181/teslamate-mqtt2telegram/-/settings/integrations)
|
## Packaging and running the application
|
||||||
|
|
||||||
## Collaborate with your team
|
The application can be packaged using:
|
||||||
|
```shell script
|
||||||
|
./mvnw package
|
||||||
|
```
|
||||||
|
It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory.
|
||||||
|
Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory.
|
||||||
|
|
||||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`.
|
||||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
||||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
||||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
||||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
|
||||||
|
|
||||||
## Test and Deploy
|
If you want to build an _über-jar_, execute the following command:
|
||||||
|
```shell script
|
||||||
|
./mvnw package -Dquarkus.package.type=uber-jar
|
||||||
|
```
|
||||||
|
|
||||||
Use the built-in continuous integration in GitLab.
|
The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`.
|
||||||
|
|
||||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
## Creating a native executable
|
||||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
||||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
||||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
||||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
||||||
|
|
||||||
***
|
You can create a native executable using:
|
||||||
|
```shell script
|
||||||
|
./mvnw package -Pnative
|
||||||
|
```
|
||||||
|
|
||||||
# Editing this README
|
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
|
||||||
|
```shell script
|
||||||
|
./mvnw package -Pnative -Dquarkus.native.container-build=true
|
||||||
|
```
|
||||||
|
|
||||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
You can then execute your native executable with: `./target/teslamate-mqtt2telegram-1.0.0-SNAPSHOT-runner`
|
||||||
|
|
||||||
## Suggestions for a good README
|
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.
|
||||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
||||||
|
|
||||||
## Name
|
## Related Guides
|
||||||
Choose a self-explaining name for your project.
|
|
||||||
|
|
||||||
## Description
|
- Camel Telegram ([guide](https://camel.apache.org/camel-quarkus/latest/reference/extensions/telegram.html)): Send and receive messages acting as a Telegram Bot Telegram Bot API
|
||||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
- Camel Core ([guide](https://camel.apache.org/camel-quarkus/latest/reference/extensions/core.html)): Camel core functionality and basic Camel languages: Constant, ExchangeProperty, Header, Ref, Simple and Tokenize
|
||||||
|
- Camel Paho MQTT5 ([guide](https://camel.apache.org/camel-quarkus/latest/reference/extensions/paho-mqtt5.html)): Communicate with MQTT message brokers using Eclipse Paho MQTT v5 Client
|
||||||
## Badges
|
|
||||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
||||||
|
|
||||||
## Visuals
|
|
||||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
||||||
|
|
||||||
## Support
|
|
||||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
||||||
|
|
||||||
## Roadmap
|
|
||||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
State if you are open to contributions and what your requirements are for accepting them.
|
|
||||||
|
|
||||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
||||||
|
|
||||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
||||||
|
|
||||||
## Authors and acknowledgment
|
|
||||||
Show your appreciation to those who have contributed to the project.
|
|
||||||
|
|
||||||
## License
|
|
||||||
For open source projects, say how it is licensed.
|
|
||||||
|
|
||||||
## Project status
|
|
||||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
||||||
|
|
|
||||||
136
pom.xml
Normal file
136
pom.xml
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.c4181</groupId>
|
||||||
|
<artifactId>teslamate-mqtt2telegram</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<properties>
|
||||||
|
<compiler-plugin.version>3.8.1</compiler-plugin.version>
|
||||||
|
<maven.compiler.release>17</maven.compiler.release>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
||||||
|
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||||
|
<quarkus.platform.version>2.13.1.Final</quarkus.platform.version>
|
||||||
|
<skipITs>true</skipITs>
|
||||||
|
<surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
|
||||||
|
</properties>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${quarkus.platform.group-id}</groupId>
|
||||||
|
<artifactId>${quarkus.platform.artifact-id}</artifactId>
|
||||||
|
<version>${quarkus.platform.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${quarkus.platform.group-id}</groupId>
|
||||||
|
<artifactId>quarkus-camel-bom</artifactId>
|
||||||
|
<version>${quarkus.platform.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.camel.quarkus</groupId>
|
||||||
|
<artifactId>camel-quarkus-telegram</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.camel.quarkus</groupId>
|
||||||
|
<artifactId>camel-quarkus-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.camel.quarkus</groupId>
|
||||||
|
<artifactId>camel-quarkus-paho-mqtt5</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-arc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jscience</groupId>
|
||||||
|
<artifactId>jscience</artifactId>
|
||||||
|
<version>4.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-junit5</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>${quarkus.platform.group-id}</groupId>
|
||||||
|
<artifactId>quarkus-maven-plugin</artifactId>
|
||||||
|
<version>${quarkus.platform.version}</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>build</goal>
|
||||||
|
<goal>generate-code</goal>
|
||||||
|
<goal>generate-code-tests</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${compiler-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-parameters</arg>
|
||||||
|
</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${surefire-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||||
|
<maven.home>${maven.home}</maven.home>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
|
<version>${surefire-plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>integration-test</goal>
|
||||||
|
<goal>verify</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||||
|
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||||
|
<maven.home>${maven.home}</maven.home>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>native</id>
|
||||||
|
<activation>
|
||||||
|
<property>
|
||||||
|
<name>native</name>
|
||||||
|
</property>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<skipITs>false</skipITs>
|
||||||
|
<quarkus.package.type>uber-jar</quarkus.package.type>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
||||||
63
src/main/java/com/c4181/camel/CamelConfiguration.java
Normal file
63
src/main/java/com/c4181/camel/CamelConfiguration.java
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.c4181.camel;
|
||||||
|
|
||||||
|
import org.apache.camel.Exchange;
|
||||||
|
import org.apache.camel.builder.RouteBuilder;
|
||||||
|
import org.apache.camel.component.telegram.model.OutgoingTextMessage;
|
||||||
|
|
||||||
|
import javax.measure.Measure;
|
||||||
|
import javax.measure.quantity.Pressure;
|
||||||
|
import javax.measure.unit.NonSI;
|
||||||
|
import javax.measure.unit.Unit;
|
||||||
|
|
||||||
|
public class CamelConfiguration extends RouteBuilder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure() {
|
||||||
|
from("paho-mqtt5:teslamate/cars/1/update_version?brokerUrl={{sys:BROKER_URL}}").process((exchange -> {
|
||||||
|
String updateVersion = exchange.getIn().getBody(String.class);
|
||||||
|
OutgoingTextMessage message = new OutgoingTextMessage();
|
||||||
|
message.setText(updateVersion);
|
||||||
|
exchange.getIn().setBody("New Update available. Version: " + message);
|
||||||
|
|
||||||
|
log.info("New Version {} found. Sending to telegram", updateVersion);
|
||||||
|
}))
|
||||||
|
.to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}");
|
||||||
|
|
||||||
|
from("paho-mqtt5:teslamate/cars/1/tpms_pressure_fl?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Front left")))
|
||||||
|
.to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}");
|
||||||
|
|
||||||
|
from("paho-mqtt5:teslamate/cars/1/tpms_pressure_fr?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Front right")))
|
||||||
|
.to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}");
|
||||||
|
|
||||||
|
from("paho-mqtt5:teslamate/cars/1/tpms_pressure_rl?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Back left")))
|
||||||
|
.to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}");
|
||||||
|
|
||||||
|
from("paho-mqtt5:teslamate/cars/1/tpms_pressure_rr?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Back right")))
|
||||||
|
.to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkTirePressure(Exchange exchange, String tire) {
|
||||||
|
double tirePressure = convertBarToPsi(exchange.getIn().getBody(double.class));
|
||||||
|
|
||||||
|
if (isTirePressureLow(tirePressure)) {
|
||||||
|
exchange.getIn().setBody(tire + " tire pressure is low: " + tirePressure);
|
||||||
|
} else if (isTirePressureHigh(tirePressure)) {
|
||||||
|
exchange.getIn().setBody(tire + " tire pressure is high: " + tirePressure);
|
||||||
|
} else {
|
||||||
|
exchange.setRouteStop(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private double convertBarToPsi(double pressure) {
|
||||||
|
return Measure.valueOf(pressure, NonSI.BAR).doubleValue((Unit<Pressure>) NonSI.POUND_FORCE.divide(NonSI.INCH.pow(2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTirePressureLow(double tirePressure) {
|
||||||
|
return tirePressure < 38;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTirePressureHigh(double tirePressure) {
|
||||||
|
return tirePressure > 48;
|
||||||
|
}
|
||||||
|
}
|
||||||
0
src/main/resources/application.properties
Normal file
0
src/main/resources/application.properties
Normal file
Loading…
Reference in a new issue