gprs <> rs232 | Telit Cinterion IoT Developer Community
November 24, 2014 - 11:37am, 4969 views
Hello everybody,
do you have a simple code to receive data from a connection and send it further to the com port, and the data i get from comport send it to the connection over gprs?
regards
For reading rs232 port you can use RS232Demo project that you got with other examples on install CD. For gprs is important which service you want to use, but basic instructions are here: https://iot-developer.thalesgroup.com/tutorial/concept-board-internet-se...
i get this code...
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.CommConnection;
import javax.microedition.io.Connector;
import javax.microedition.io.ServerSocketConnection;
import javax.microedition.io.SocketConnection;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.cinterion.io.ATCommandFailedException;
public class Main extends MIDlet {
public Main() {
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
System.out.println("Stopped");
notifyDestroyed();
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
System.out.println("Start");
while (true) {
try {
// wait for registration
GsmUtils.waitForRegistration();
// wait for incoming connection
ServerSocketConnection server = (ServerSocketConnection) Connector
.open("socket://:1234;bearer_type=gprs;access_point=m2m.plusgsm.pl;username=user;password=pswd");
Logger.info(
"Waiting for incoming connection on: "
+ server.getLocalAddress() + ":"
+ server.getLocalPort(), Main.class);
SocketConnection socket = (SocketConnection) server
.acceptAndOpen();
InputStream socket_in = socket.openInputStream();
OutputStream socket_out = socket.openOutputStream();
server.close();
Logger.info("Remote host connected.", Main.class);
// open RS232 connection
Logger.info("Open serial connection.", Main.class);
CommConnection serial = (CommConnection) Connector
.open("comm:COM0;baudrate=19200");
DataInputStream serial_in = serial.openDataInputStream();
DataOutputStream serial_out = serial.openDataOutputStream();
Logger.info("Open serial connection: done.", Main.class);
// bridge streams
Logger.info("Bridge streams.", Main.class);
StreamBridge bridge_1 = new StreamBridge(serial_in, socket_out);
StreamBridge bridge_2 = new StreamBridge(socket_in, serial_out);
bridge_1.start();
bridge_2.start();
Logger.info("Bridge streams: done", Main.class);
// wait until remote host disconnects
bridge_2.join();
// clean resources
Logger.info("Clean resources.", Main.class);
try {
socket_in.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
socket_out.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
socket.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
serial_in.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
serial_out.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
serial.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Logger.info("Clean resources: done.", Main.class);
// loop
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Hello everybody,
Where can I find StreamBridge? Is it any library?
regards
I suppose that this is just a class being part of the DERLICH's project. It's probably a thread that reads from one stream and pushes it all to another. Maybe also adds some buffering.
I uploaded my project to dropbox:
https://www.dropbox.com/s/xsqvnwie31k5hgq/isafinal.zip?dl=0
thank you very much Antonio
regards
Thanks. You save me a lot
Is there another possibilitiy to establish a secure connection?
Could you explain a little bit more what would you like to do?
In MIDlet you can use SecureConnection instead of SocketConnection.
Regards,
Bartłomiej