Skip to content

Commit

Permalink
relaxed response code when calling out to other services, require upn…
Browse files Browse the repository at this point in the history
…p.config.address on startup instead of default
  • Loading branch information
armzilla committed Sep 16, 2016
2 parents df39d54 + d6aebfb commit 8030817
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RUN mvn install

EXPOSE 8080

CMD ["bash", "-c", "java -jar target/amazon-echo-bridge-*.jar --upnp.config.address=$(ip route get 8.8.8.8 | egrep -o '[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\s*$')"]
CMD ["bash", "-c", "java -Xmx256M -jar target/amazon-echo-bridge-*.jar --upnp.config.address=$(ip route get 8.8.8.8 | egrep -o '[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\s*$')"]
9 changes: 7 additions & 2 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ After the application is started and running, you can access the configurator by

Input your devices using the form at the bottom of the page, add command URLs to parse (useful if you use a system like OpenHAB), and save.

Instruct your Amazon Echo to take control of your devices by saying "Alexa, discover my devices" and your all set!
Instruct your Amazon Echo to learn about your devices by saying "Alexa, discover my devices" and your all set!

## Using

You can now control devices with your Amazon Echo by saying "Alexa, Turn on the office light" or other names you have given your configured devices.

To view or remove devices that Alexa knows about, you can use the mobile app Menu / Settings / Connected Home, This is needed if you remove a device from the Amazon Echo Bridge.

## Build

Expand All @@ -49,7 +54,7 @@ To build the jar file yourself, make your changes and simply run Maven like this
mvn install
```

Then locate the jar and start the server using the instructions above.
Then locate the jar and start the server using the instructions above. By default maven will put the jar file in the target directory. ```java -jar target/amazon-echo-bridge-*.jar```

## POST/PUT REST API

Expand Down
115 changes: 56 additions & 59 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,67 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.armzilla.ha</groupId>
<artifactId>amazon-echo-bridge</artifactId>
<version>0.2.1</version>
<packaging>jar</packaging>
<groupId>com.armzilla.ha</groupId>
<artifactId>amazon-echo-bridge</artifactId>
<version>0.2.1</version>
<packaging>jar</packaging>

<name>Amazon Echo Bridge</name>
<description>Emulates a Philips Hue bridge to allow the Amazon Echo to integrate seamlessly into various home automation systems.</description>
<name>Amazon Echo Bridge</name>
<description>Emulates a Philips Hue bridge to allow the Amazon Echo to integrate seamlessly into various home
automation systems.
</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.6.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.armzilla.ha.SpringbootEntry</start-class>
<java.version>1.8</java.version>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.armzilla.ha.SpringbootEntry</start-class>
<java.version>1.8</java.version>
<httpclient.version>4.5.1</httpclient.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<!--<dependency>--> <!-- was going to use this templating urls but that got bloated -->
<!--<groupId>org.freemarker</groupId>-->
<!--<artifactId>freemarker</artifactId>-->
<!--<version>2.3.22</version>-->
<!--</dependency>-->
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
</dependencies>

</project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
22 changes: 22 additions & 0 deletions src/main/java/com/armzilla/ha/ConfigChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.armzilla.ha;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
* Created by arm on 9/16/16.
*/
@Component
public class ConfigChecker implements InitializingBean {

@Value("${upnp.config.address}")
private String responseAddress;

@Override
public void afterPropertiesSet() throws Exception {
if(responseAddress == null || responseAddress.isEmpty() ){
throw new IllegalArgumentException("please provide the IP(v4) address of the interface you want the bridge to listen on using --upnp.config.address=<ipadress>");
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/armzilla/ha/SpringbootEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
Expand All @@ -20,6 +21,5 @@ public class SpringbootEntry {
public static void main(String[] args) {
SpringApplication.run(SpringbootEntry.class, args);
}



}
5 changes: 3 additions & 2 deletions src/main/java/com/armzilla/ha/hue/HueMulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ protected boolean doHttpRequest(String url, String httpVerb, String contentType,
try {
HttpResponse response = httpClient.execute(request);
EntityUtils.consume(response.getEntity()); //close out inputstream ignore content
log.info("GET on URL responded: " + response.getStatusLine().getStatusCode());
if(response.getStatusLine().getStatusCode() == 200){
int httpResponseCode = response.getStatusLine().getStatusCode();
log.info("GET on URL responded: " + httpResponseCode);
if(httpResponseCode >= 200 && httpResponseCode < 300){ //had complaints that some apps do not respond back with pure 200
return true;
}
} catch (IOException e) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/armzilla/ha/upnp/UpnpListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ public class UpnpListener {
@Value("${emulator.portcount}")
private int portCount;

@Value("${upnp.disable}")
private boolean disable;

@Autowired
private ApplicationContext applicationContext;

@Scheduled(fixedDelay = Integer.MAX_VALUE)
public void startListening(){

if (disable) {
return;
}

log.info("Starting UPNP Discovery Listener");

try (DatagramSocket responseSocket = new DatagramSocket(upnpResponsePort);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
upnp.response.port=50000
upnp.config.address=192.168.1.1
devices.per.gateway=5
upnp.config.address=
emulator.portbase=8080
emulator.portcount=3
upnp.disable=false

0 comments on commit 8030817

Please sign in to comment.