diff --git a/README.md b/README.md index 2740a3f..0f7d73c 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,11 @@ This project provides a Spring Boot Starter to use the Pi4J V2 library in your S * After the application has launched, open a browser and check: * http://localhost:8080/actuator/health * http://localhost:8080/actuator/info + * Change the connected components: + * LED on: http://localhost:8080/api/pi4j/led/true + * LED off: http://localhost:8080/api/pi4j/led/false + * Get the button state: http://localhost:8080/api/pi4j/button + * Set text on the LCD: http://localhost:8080/api/pi4j/lcd/0/test ## Running the sample application on a Raspberry Pi @@ -67,6 +72,26 @@ $ sudo ~/.sdkman/candidates/java/19.0.2-zulu/bin/java -jar pi4j-spring-boot-star ```shell + . ____ _ __ _ _ + /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ +( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ + \\/ ___)| |_)| | | | | || (_| | ) ) ) ) + ' |____| .__|_| |_|_| |_\__, | / / / / + =========|_|==============|___/=/_/_/_/ + :: Spring Boot :: (v3.2.5) + +[pi4j-spring-boot-sample-app] [ main] c.p.spring.boot.sample.app.Application : Starting Application using Java 22.0.2 with PID 62220 (/Users/frank/Documents/GitHub/pi4j-springboot/pi4j-spring-boot-starter-sample-app/target/classes started by frank in /Users/frank/Documents/GitHub/pi4j-springboot) +[pi4j-spring-boot-sample-app] [ main] c.p.spring.boot.sample.app.Application : No active profile set, falling back to 1 default profile: "default" +[pi4j-spring-boot-sample-app] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) +[pi4j-spring-boot-sample-app] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] +[pi4j-spring-boot-sample-app] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.20] +[pi4j-spring-boot-sample-app] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext +[pi4j-spring-boot-sample-app] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 375 ms +[pi4j-spring-boot-sample-app] [ main] com.pi4j.Pi4J : New auto context +[pi4j-spring-boot-sample-app] [ main] com.pi4j.Pi4J : New context builder +[pi4j-spring-boot-sample-app] [ main] c.pi4j.boardinfo.util.BoardInfoHelper : Detected OS: Name: Mac OS X, version: 15.0, architecture: aarch64 +[pi4j-spring-boot-sample-app] [ main] c.pi4j.boardinfo.util.BoardInfoHelper : Detected Java: Version: 22.0.2, runtime: 22.0.2+9, vendor: Azul Systems, Inc., vendor version: Zulu22.32+15-CA +... ``` * Open browser with http://{RASPBERRY_PI_IP_ADDRESS}:8080/actuator/info @@ -133,6 +158,5 @@ $ sudo ~/.sdkman/candidates/java/19.0.2-zulu/bin/java -jar pi4j-spring-boot-star This project was started by Daniel Frey and got further improved by DaShaun Carter during a few live-coding sessions: -1. TODO link to first Twitch -2. [Working on Pi4J Spring Boot](https://www.twitch.tv/videos/1828406758) -3. [Spring Boot Pi4J Starter :: Testing my PR](https://www.twitch.tv/videos/1829189803) \ No newline at end of file +1. [Working on Pi4J Spring Boot](https://www.twitch.tv/videos/1828406758) +1. [Spring Boot Pi4J Starter :: Testing my PR](https://www.twitch.tv/videos/1829189803) \ No newline at end of file diff --git a/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/ContextConfiguration.java b/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/ContextConfiguration.java index b9d7d13..58720b5 100644 --- a/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/ContextConfiguration.java +++ b/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/ContextConfiguration.java @@ -1,18 +1,7 @@ package com.pi4j.spring.boot; import com.pi4j.Pi4J; -import com.pi4j.boardinfo.definition.BoardModel; -import com.pi4j.boardinfo.util.BoardInfoHelper; import com.pi4j.context.Context; -import com.pi4j.plugin.mock.platform.MockPlatform; -import com.pi4j.plugin.mock.provider.gpio.analog.MockAnalogInputProvider; -import com.pi4j.plugin.mock.provider.gpio.analog.MockAnalogOutputProvider; -import com.pi4j.plugin.mock.provider.gpio.digital.MockDigitalInputProvider; -import com.pi4j.plugin.mock.provider.gpio.digital.MockDigitalOutputProvider; -import com.pi4j.plugin.mock.provider.i2c.MockI2CProvider; -import com.pi4j.plugin.mock.provider.pwm.MockPwmProvider; -import com.pi4j.plugin.mock.provider.serial.MockSerialProvider; -import com.pi4j.plugin.mock.provider.spi.MockSpiProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -28,26 +17,9 @@ public class ContextConfiguration { public ContextConfiguration() { try { - if (BoardInfoHelper.current().getBoardModel() == BoardModel.UNKNOWN) { - logger.warn("The Pi4J library could not detect that this system is a Raspberry Pi board."); - logger.warn("For this reason, Mock implementations will be loaded for all I/O."); - logger.warn("This means, you can test most functionality of the Pi4J library, but it will not try to interact with I/Os."); - this.pi4j = Pi4J.newContextBuilder() - .add(new MockPlatform()) - .add(MockAnalogInputProvider.newInstance(), - MockAnalogOutputProvider.newInstance(), - MockSpiProvider.newInstance(), - MockPwmProvider.newInstance(), - MockSerialProvider.newInstance(), - MockI2CProvider.newInstance(), - MockDigitalInputProvider.newInstance(), - MockDigitalOutputProvider.newInstance()) - .build(); - } else { - this.pi4j = Pi4J.newAutoContext(); - } - } catch (Error e) { - logger.error("Pi4J library failed to load: {}", e.getMessage()); + this.pi4j = Pi4J.newAutoContext(); + } catch (Exception e) { + logger.error("Pi4J library failed to initialize: {}", e.getMessage()); } } diff --git a/pom.xml b/pom.xml index 28fb694..d9e972f 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ 17 3.2.5 - 2.6.1 + 2.7.0 0.8.10