Archiv des Autors: dka

Connecting Arduino and Android wirelessly via WiFi using the RN-XV WiFly Module

The idea was to establish some kind of wireless connection between an Arduino (Mega in my case) and an Android phone (on 4.0 currently). The final idea is to remote control a quadrocopter using this link. Therefore there are some basic limitations – it should have a reasonable range and should not need any additional infrastructure (like Access Points or the like). The only options that come to mind is Bluetooth (probably a bit short in range) and WiFi; NFC can be excluded (only a few cm range). My first try was WiFi.

The RN-XV WiFly module is a comparatively cheap WiFi / WLAN module that can be used with Arduino. It connects to the Arduino using a serial link (UART).  Note, that it is powered with 3.3V and that it can take some power (according to the datasheet). Therefore it should be powered with a separate regulator as the one that is integrated on the Arduino board provides too less power (at least to specs, but I didn’t want to risk frying it). Besides that, one needs to bring the TTL level (5V) of Arduino down to 3.3V as well, which can be easily done using a voltage divider.

The schematics for hooking it up:

602a0a4b81

The RN-XV WiFly supports an AdHoc Mode (connect pin 8 to 3.3V). In this mode it creates an AdHoc network that you can easily connect to with a computer. Afterwards you can telnet to the module and configure it and to talk to the Arduino.

AdHoc-Mode sounded create for my use case and works really flawlessly with any computer. Unfortunately Android does not support joining AdHoc networks by default (there are some hacks that involve rooting the phone). Therefore this mode can’t be used here. Ok, so let’s try the other way round – open a HotSpot on your Android phone and let the RN-XV WiFly connect to it. This actually works really good. There’s one limitation here – you can’t open the HotSpot programmatically (not supported by the API). This means that users of your app would need to do that manually (which is not too big of a problem as this is DIY space anyway :-). So here’s how to do it.

First, open the HotSpot on your phone choosing an SSID and a password. Also, you might want to disable that the HotSpot switches itself off if there’s no activity for a certain amount of time. On my HTC One X it looks like this:

4134b8aacb

Second, configure the RN-XV WiFly module. Do this by putting the module in AdHoc Mode (connect pin 8 to 3.3V) and connect a computer to the network. Then, telnet to 169.254.1.1, port 2000. I used these commands for configuration:

$$$     // Enter command mode

set sys printlvl 0     // Disables debug output
set uart baud 115200     // Set baudrate on UART interface to Arduino
set wlan auth 3
set wlan phrase YOURPASSPHRASE
set wlan ssid YOURSSID
set wlan rate 8      // 6 Mbit/s - according to docs lowering the data rate increases range
save
reboot

Third, put a test program to the Arduino. I used the MultiSerial example from the Arduino site, slightly modified:

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial3.begin(115200);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial3.available()) {
    int inByte = Serial3.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial3.write(inByte);
  }
}

Fourth, test the connection with your computer. Open the serial monitor from the Arduino IDE alongside your telnet connection to the module (still running in AdHoc). You should be able to type something in the telnet session and see it on the serial monitor and vice versa.

Last but not least we need an Android app. I will not go into the details of creating an Android app here (Google provides good docs on it). Here’s the source code for connecting a socket to the first (and hopefully the only) client of your HotSpot and send some chars to it.

InetAddress in;
try {
 List<ClientScanResult> clients = getClientList(true, 500);
 for (ClientScanResult client : clients) {
  Log.d(TAG, "Found client " + client.getHWAddr() + " " + client.getDevice() + " " + client.getIpAddr());
 }

 in = InetAddress.getByName(clients.get(0).getIpAddr());
 if (in.isReachable(500)) {
  Log.d(TAG, "Arduino reachable");
  socket = new Socket(in, 2000);
  for (int i = 0; i < 7; i++) {
   // Read *HELLO*
   socket.getInputStream().read();
  }
 } else {
  Log.d(TAG, "Arduino not reachable");
 }
} catch (UnknownHostException e) {
 Log.e(TAG, "Could not connect: " + e.getMessage(), e);
} catch (IOException e) {
 Log.e(TAG, "Could not connect: " + e.getMessage(), e);
}

Note that the getClientList() method (called in line 3) and the ClientScanResult class is from Whitebyte. Thanks for this!

And that’s it. You now have a wireless connection between Arduino and Android that you can use just like a serial link.

Connecting an Arduino to EIB/KNX

Update 14.07.2015: We are currently thinking about producing an Arduino KNX shield. Please let us know if you are interested. Thanks!

After having heard about it a couple of times already, I recently rediscovered the Arduino for myself and quickly came up with an idea for a first project – connecting it to KNX (formerly known as EIB). This was actually quite easy and I’d like to share my experience (and code) here in case somebody wants to do a similar thing.

To interface with KNX an interface IC is required (at least if you’re not able to build one on your own). I used a Siemens TP-UART for the job (obtained from Opternus Components). The TP-UART converts the signal from KNX to a UART signal (compatible with Arduino’s serial ports) and cares for a lot of the low-level details, e.g. line access control and telegram repetition. The serial protocol is described in depth in the TP-UART datasheet.

To connect the TP-UART to KNX you need some rather standard parts (resistors, capacitors, diodes, a crystal, …). To a large extend I used a schematic designed by the TU of Vienna for their TP-UART PC Interface Board. On the Arduino side I added optocouplers to isolate from KNX. The full schematic is as follows (you can find the Eagle files in the Bitbucket repository):

b4165158c9

I built it up on a breadboard for now using an Arduino Mega 2560. Using the Mega is the simplest solution as it has multiple UARTs so that you can connect the usual USB for programming and the TP-UART at the same time. This makes debugging using the serial “console” easy.

IMG_5613

Next, I needed some software. After fiddling around with the Arduino IDE for a short time, I noticed it’s pretty limited (at least if you’re used to full-fledged environments like Eclipse). So I quickly started building a library in Eclipse. The library has a comparably simple interface to the user such that he/she doesn’t have to care about the details of the KNX / TP-UART protocol. While implementing the library I needed some time to figure out the details of the protocol (e.g. when I need to send the ACK / NACK confirmation on an incoming telegram). Overall however it was not too difficult.

The whole source code of the library can be found on my Bitbucket repository for this project. There are also some examples in there that show the use of the library. The first “real” example is the use of a Dallas temperature sensor and sending its values to KNX in regular intervals and also answering to read requests on a certain group address – in the repository the “TemperatureReadoutOneWire” example.

Feel free to use the library for anything you want (of course without any warranty). If you have any improvements, suggestions or found a bug please let me know e.g. by using the issue tracker.

Creating a web service with Spring WS using JAXB2 marshalling

In the following the steps are shown how to create a simple web service with the Spring Web Service Framework using a JAXB2 marshalling. The example web service produces a list of random numbers. The amount of random numbers generated is specified in the request.

Prerequisites:

  • Eclipse Helios (3.6)
  • Installed m2eclipse plugin – this is not absolutely necessary, if you don’t want to use it, you can perform the Maven steps on the command line

First, we create a Maven project using the Spring WS archetype.

86a6a511406bc0f59463 221db397f3 c9807cc54e

Next, we change the dependency versions in the generated POM file to the current stable version (1.5.9) of Spring WS. Additionally we’re using Java version 1.5 and add the Jetty plugin for testing the service later.

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.dkaedv.testws</groupId>
  <artifactId>randomnumbers</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>randomnumbers Spring-WS Application</name>
  <url>http://www.springframework.org/spring-ws</url>
  <build>
    <finalName>randomnumbers</finalName>
    <plugins>
      <plugin>
        <inherited>true</inherited>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.10</version>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.springframework.ws</groupId>
      <artifactId>spring-oxm-tiger</artifactId>
      <version>1.5.9</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.ws</groupId>
      <artifactId>spring-ws-core-tiger</artifactId>
      <version>1.5.9</version>
    </dependency>
  </dependencies>
</project>

To let Eclipse know about the changes in the POM, we update the project configuration by right-clicking on the project -> Maven -> Update Project Configuration.

Next, we need to create an XML Schema for our service. Therefore we create a folder „xsd“ within src/main/webapp/WEB-INF and create the following „randomnumbers.xsd“ in there. The data structure itself is very simple. It contains two elements, the RandomNumbersRequest with the amount parameter and the RandomNumbersResponse containing a list of numbers.

Note, that the element names conform to the Spring naming conventions, i.e. the suffixes „Request“ and „Response“.

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.dka-edv.com/RandomNumbers"
 xmlns:tns="http://www.dka-edv.com/RandomNumbers" elementFormDefault="qualified">

 <element name="RandomNumbersRequest">
    <complexType>
      <sequence>
        <element name="amount" type="int" />
      </sequence>
    </complexType>
  </element>

  <element name="RandomNumbersResponse">
    <complexType>
      <sequence>
        <element name="number" type="int" minOccurs="1" maxOccurs="unbounded"/>
      </sequence>
    </complexType>
  </element>
</schema>

From this XSD the interface classes for the request and response can be generated. These classes will be used by the JAXB2 marshaller to convert the web service requests and responses from/to XML. The code generation is configured by adding the appropriate build plugin in pom.xml:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>jaxb2-maven-plugin</artifactId>
  <version>1.3</version>
  <executions>
    <execution>
      <goals>
        <goal>xjc</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <packageName>com.dkaedv.testws.randomnumbers</packageName>
    <schemaDirectory>src/main/webapp/WEB-INF/xsd/</schemaDirectory>
    <schemaFiles>randomnumbers.xsd</schemaFiles>
    <outputDirectory>${basedir}/src/generated/java</outputDirectory>
  </configuration>
</plugin>

To actually generate code, run the generate-source target. This can be done in Eclipse by running the project as Maven build or on the command line:

mvn generate-sources

Afterwards, create the folder src/main/java to be able to implement the actual web service endpoint. Afterwards, refresh the project in Eclipse and update the Maven project configuration as before (Right-click the Project -> Maven -> Update Project Configuration).

Next, create the class RandomNumbersEndpoint as a subclass of AbstractMarshallingPayloadEndpoint that contains the implementation of the service:

973be1ffb8

package com.dkaedv.testws.randomnumbers;

import org.springframework.oxm.Marshaller;
import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint;

import com.dkaedv.testws.randomnumbers.RandomNumbersRequest;
import com.dkaedv.testws.randomnumbers.RandomNumbersResponse;

public class RandomNumbersEndpoint extends AbstractMarshallingPayloadEndpoint {

  public RandomNumbersEndpoint(Marshaller marshaller) {
    super(marshaller);
  }

  @Override
  protected Object invokeInternal(Object request) throws Exception {
    RandomNumbersRequest rnReq = (RandomNumbersRequest) request;
    RandomNumbersResponse response = new RandomNumbersResponse();

    int n = rnReq.getAmount();

    for (int i = 0; i < n; i++) {
      int randomNumber = (int) (Math.random() * 1000);
      response.getNumber().add(randomNumber);
    }

    return response;
  }
}

As the final step, we need to add the appropriate configuration to spring-ws-servlet.xml.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

  <!-- Publish the WSDL
         at http://localhost:8080/randomnumbers/randomNumbersService/randomNumbers.wsdl -->
  <bean id="randomNumbers" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
    <property name="schema" ref="schema" />
    <property name="portTypeName" value="RandomNumbersPT" />
    <property name="locationUri" value="http://localhost:8080/randomnumbers/randomNumbersService/" />
  </bean>

  <bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
    <property name="xsd" value="/WEB-INF/xsd/randomnumbers.xsd" />
  </bean>

  <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
      <list>
        <value>com.dkaedv.testws.randomnumbers.RandomNumbersRequest</value>
        <value>com.dkaedv.testws.randomnumbers.RandomNumbersResponse</value>
      </list>
    </property>
    <property name="schema" value="/WEB-INF/xsd/RandomNumbers.xsd"/>
  </bean>

  <!-- Endpoint Definiton -->
  <bean id="randomNumbersEndpoint" class="com.dkaedv.testws.randomnumbers.RandomNumbersEndpoint">
    <constructor-arg ref="marshaller" />
  </bean>

  <!-- Routing -->
  <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
    <property name="mappings">
      <props>
        <prop key="{http://www.dka-edv.com/RandomNumbers}RandomNumbersRequest">randomNumbersEndpoint</prop>
      </props>
    </property>
    <property name="interceptors">
      <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
    </property>
  </bean>
</beans>

That’s it. You can run the project using the Maven target „jetty:run“, e.g. on the command line:

mvn jetty:run

The WSDL should now be accessible at the address http://localhost:8080/randomnumbers/randomNumbersService/randomNumbers.wsdl. Note, that the WSDL was generated by Spring from the XML Schema created earlier – a manual creation is not required.

Of course you can now access and test the web service by using soapUI for example.

rencontre femme lievin


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
prostituee sur auxerre
rencontres jeunes catholiques paris
rencontre homme convertis islam
site de rencontre au travail
au nom de la vérité une mauvaise rencontre sur le net
rencontre femme de bejaia
prostituées lille rue
rencontre femmes anglet
rencontre souvenir jeannot bouchard
rencontre troisieme type musique couleur
dating femme haute savoie
dans quelle bd tintin rencontre haddock
rencontre japonaise lyon
verhuren aan prostituees
rencontre femme polynesie
rencontres entre noirs et blancs
le boncoin.fr rencontre
souhaiter un anniversaire de rencontre
rencontre emploi
dating femmes saint martin
rencontre ronde forum
soirees rencontres paris
rencontre femme bejaia
trouver pseudo rencontre
cite de rencontre belge pour jeune
chat nimes
site de rencontre mec pansement
agence rencontre zoosk
berlusconi prostituee marocaine
rencontre au jardin langlade
donner son avis sur les sites de rencontre
rencontre montagne
site de rencontre oui ou non
rencontres cazaubon
site de rencontre homme agé
rencontres autour de la bd gruissan
point rencontre gare saint jean bordeaux
rencontre de royal et hollande à l’onu
site rencontre rouen
agrirencontre com
recherche femme pour rencontre gratuite
rencontre uk
chanson rencontre jonasz
rencontre bouledogue francais alsace
rencontre mandeure
rencontres armeniennes
rencontres mondiales nantes
rencontres ardennes
rencontre rivière-du-loup
le jour où je l’ai rencontrée vf
zemzem site de rencontre gratuit
sbk site de rencontre
rencontre sherbrooke gratuit
meet bobigny
rencontre bouira
rencontre judo france japon
klanten prostituee
agence de rencontre st jerome
tarifs prostituées france
site de rencontre meet me
agence rencontres faucon
phrase sur rencontres
encontre a equação da reta normal
quand on rencontre l’ame soeur
art tv elle rencontre
site de rencontre cafe
rencontre charleroi le qui vient moi
sms notre rencontre
exemple de mail rencontre
rencontre femme juive marseille
15 rencontres rhodaniennes
rencontre martigny valais
des sites de rencontre pour ado
lieux de rencontres 74
sites de rencontres marseille
prix prostituée chinoise paris
site de rencontre rap
prostituées francaises
rencontre single
rencontre entre molière et lully
agence de rencontre tarif
rencontre saint sulpice les feuilles
site de rencontre geek gay
notre rencontre traduction anglais
culture et rencontre lancy
rencontres pedagogiques d’été
rencontre femme sexe talence
turbo rencontre
prostituée paris 20
rencontres ufologiques
rencontres seniors gratuit
lieu de rencontre en isere
site de rencontre yaoundé
a la rencontre tf2
rencontre sexe le cannet
skype site de rencontre
rencontre à deux
rencontres nationales des scot 2012
rencontres technologiques france israel
rencontre avec les robinsons