ings
Member level 4
- Joined
- Sep 8, 2014
- Messages
- 78
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 988
<4.00> Joining wifi now..
Associated!
DHCP: Start
DHCP in 4319ms, lease=86400s
IF=UP
DHCP=ON
IP=192.168.1.5:2000
NM=255.255.255.0
GW=192.168.1.1
set ip protocol 1
AOK
<4.00> set ip host 192.168.1.4
AOK
<4.00> set ip remote 999
AOK
<4.00> set ip local 2000
AOK
set sys auto 10 // Automatically connect every 10 seconds
set option format 7 // Send the header and sampled binary data converted to ASCII
set q sensor 0xFF // Set the sensor mask to sample all channels
save // Save the configuration to the config file
reboot // Reboot so that the settings take effect
PIC24 to RN171 test
CMD
join
Auto-Assoc ssid chan=1 mode=MIXED SCAN OK
<4.00> Joining ssid now..
Associated!
DHCP: Start
DHCP in 1855ms, lease=86400s
IF=UP
DHCP=ON
IP=192.168.1.64:2000
NM=255.255.255.0
GW=192.168.1.254
set ip protocol 8
AOK
<4.00> open 192.168.1.65 20000
Connect to 192.168.1.65:20000
<4.00> *OPEN*CTRL/A hit - transmit ADC data to RN171
transmitting adc = 52
transmitting adc = 52
transmitting adc = 52
transmitting adc = 52
transmitting adc = 440
transmitting adc = 645
transmitting adc = 799
transmitting adc = 260
TCP server on IP address 192.168.1.65 port 20000
TCP server starting: IP address PC/192.168.1.65 port 20000
Client connect from IP address /192.168.1.64 port 57303
*HELLO*transmitting ADC values
adc = 52
adc = 52
adc = 52
adc = 52
adc = 440
adc = 645
adc = 799
adc = 260
// server which waits for messages from a client
import java.io.*;
import java.util.*;
import java.net.*;
public class TCPserver extends Thread
{
private ServerSocket serverSocket;
InputStream br=null;
OutputStream pw=null;
int receivePort; // port to receive from
boolean threadRunning = true; // flag to terminate thread
TCPserver(int receivePort) // constructor to receive on port receivePort
{
this.receivePort = receivePort;
}
// terminate the thread by setting flag
public void stopTCPserver()
{
threadRunning = false;
}
public void run() // thread run method, receives and buffers datagrams
{
Socket socket=null;
try
{
while (threadRunning)
{
System.out.println("TCP server starting: IP address "
+ InetAddress.getLocalHost().toString() + " port " + receivePort );
serverSocket = new ServerSocket(receivePort);
socket = serverSocket.accept(); // Wait for client to connect.
System.out.println("Client connect from IP address " + socket.getInetAddress()
+ " port " + socket.getPort());
br = socket.getInputStream();
pw = socket.getOutputStream() ;
while(threadRunning)
try
{
int code = br.read();
//System.out.println( "Server received byte: '" + code + "' char " + (char) code);
if(code==13) System.out.println(); // newline
else System.out.print( (char) code);
}
catch (Exception se) {System.err.println("done"); break;}
serverSocket.close();
}
}
catch (Exception se) {System.err.println("run() " + se); }
System.exit(1); // exit on failure
}
public static void main(String args[])
{
int receivePort=20000; // port to receive datagrams on
try
{
System.out.println("TCP server on IP address " + InetAddress.getLocalHost().getHostAddress() + " port " + receivePort);
TCPserver frameInput = new TCPserver(receivePort); // create server to receive messages
frameInput.start(); // and start it
}
catch (Exception se) {System.err.println("main() " + se); }
}
}
thanks for your response but in my case i don't use the EXplrer16; i would like just to use the RN-171-EK;It is possible to detct the analogic value just with RN171-EK or it is ncessary too usee the explorer 16
<4.00> join
Auto-Assoc ssid chan=1 mode=MIXED SCAN OK
<4.00> Joining SSID now..
Associated!
DHCP: Start
DHCP in 1966ms, lease=86400s
IF=UP
DHCP=ON
IP=192.168.1.64:2000
NM=255.255.255.0
GW=192.168.1.254
Listen on 2000
<4.00> set q s 0x0c sample sensors 2 and 3
AOK
<4.00> set b a 192.168.1.65 set broadcast address
AOK
<4.00> set b p 999 set broadcast port
AOK
<4.00> set b i 7 set broadcast interval 1 packet every 8 seconds
AOK
UDP server on IP address 192.168.1.65 port 999
From IP /192.168.1.64 UDP string received - length 110
battery volts 2796
Sensors 0 0 0 0 0 3 0 12 0 0 0 0 0 0 0 0 0 0
Sensor 2 = 48 Sensor 3 = 192
UDP data 'X*5(V|*******H****Time NOT SET**wifly-EZX Ver 4.00.1, Apr 19testRN171----------------------*:'
From IP /192.168.1.64 UDP string received - length 110
battery volts 2796
Sensors 0 0 0 0 0 9 62 23 0 0 0 0 0 0 0 0 0 0
Sensor 2 = 144 Sensor 3 = 254320
UDP data 'X*5(V|************Time NOT SET**wifly-EZX Ver 4.00.1, Apr 19testRN171----------------------*:'
From IP /192.168.1.64 UDP string received - length 110
battery volts 2797
Sensors 0 0 0 0 62 20 63 14 0 0 0 0 0 0 0 0 0 0
Sensor 2 = 254272 Sensor 3 = 258272
UDP data 'X*5(V|************Time NOT SET**wifly-EZX Ver 4.00.1, Apr 19testRN171----------------------*:'
// simple server waiting for datagrams and extracting ans displaying string
import java.io.*;
import java.util.*;
import java.net.*;
public class UDPserver extends Thread
{
public static void main(String args[])
{
try
{
// get machine IP address - two methods
int receivePort=999, i; // port to receive datagrams from
//Socket soc = new Socket("192.168.1.1", 80);
//System.out.println("UDP server on IP address " + soc.getLocalAddress().getHostAddress() + " port " + receivePort);
//soc.close();
System.out.println("UDP sevrer on IP address " + InetAddress.getLocalHost().getHostAddress() + " port " + receivePort);
InetAddress remoteIPaddress; // IP address of remote host
int remotePort; // port on remote host to send frames too
byte[] buffer = new byte[65507]; // array to put datagrams in
DatagramPacket dp = new DatagramPacket(buffer, buffer.length); // create packet for datagrams
// open DatagramSocket to receive and a DatagramePacket to hold the datagrams
DatagramSocket ds = new DatagramSocket(receivePort);
// loop forever reading datagrams from the DatagramSocket
while (true)
{
ds.receive(dp); // wait for next datagram
byte[] data = dp.getData(); // get datagram contents
System.out.println("\nFrom IP " + dp.getAddress() +" UDP string received - length " + dp.getLength() );
// display battery voltage
System.out.println("battery volts " + ((data[14]<<8) +data[15]) );
// print the sensor bytes - 16 bytes array index starting at 93 (not 94)
System.out.print("Sensors ");
for (i=93;i<=dp.getLength();i++)
System.out.print(" " + ((data[i])));
// print sensor 2 and 3 values
System.out.println("\nSensor 2 = " + (((data[97]<<8) +data[98])<<4) + " Sensor 3 = " + (((data[99]<<8) +data[100])<<4));
// print datagram contents (replace none printing characters with *)
for (i=0;i<dp.getLength();i++)
if(data[i]<32) data[i]='*';
String s = new String(data, 0, 93); // create a string from the data
System.out.println(" UDP data '" + s + "'\n");
}
}
catch (IOException se) {System.err.println("error " + se);}
System.exit(1); // exit on failure
}
}
thanks for your response but in my case i don't use the EXplrer16; i would like just to use the RN-171-EK;It is possible to detct the analogic value just with RN171-EK or it is ncessary too usee the explorer 16
join
Auto-Assoc SSID chan=1 mode=MIXED SCAN OK
<4.00> Joining SSID now..
Associated!
DHCP: Start
DHCP in 1691ms, lease=86400s
IF=UP
DHCP=ON
IP=192.168.1.64:2000
NM=255.255.255.0
GW=192.168.1.254
Listen on 2000
set ip h 192.168.1.65 set TCP server IP
AOK
<4.00> set ip r 80 set TCP server port for HTTP
AOK
<4.00> set i p 18 enable TCP and HTTP client mode
AOK
<4.00> set o f 7 append sensor data to HTTP
AOK
<4.00> set b i 7 set broadcast 1 packet every 8 seconds
AOK
<4.00> open open TCP client connection
<4.00> *OPEN*
ready to receive TCP from socket 80
TCP server starting: IP address bb-TOSH/192.168.1.65 port 80
TCP Client connect from IP address /192.168.1.64 port 20472
TCP data '*HELLO*0D11000000003DFC000C0000000000000000 HTTP/1.0
Host: dns1
'
sensor 2 0x3DFC sensor 3 0x00C0
sensor 2 15868 sensor 3 192
TCP data '*HELLO*0D11000000000007000D0000000000000000 HTTP/1.0
Host: dns1
'
sensor 2 0x0007 sensor 3 0x00D0
sensor 2 7 sensor 3 208
TCP data '*HELLO*0D11000000003E243F110000000000000000 HTTP/1.0
Host: dns1
'
sensor 2 0x3E24 sensor 3 0xF110
sensor 2 15908 sensor 3 61712
// TCP server which waits for messages from a client
import java.io.*;
import java.util.*;
import java.net.*;
public class TCPserver extends Thread
{
private ServerSocket serverSocket;
InputStream br=null;
OutputStream pw=null;
int receivePort; // port to receive from
boolean threadRunning = true; // flag to terminate thread
TCPserver(int receivePort) // constructor to receive datagrams on port receivePort
{
this.receivePort = receivePort;
}
// terminate the thread by setting flag
public void stopTCPserver()
{
threadRunning = false;
}
public void run() // thread run method, receives and buffers datagrams
{
Socket socket=null;
int frame=0;
try
{
while (threadRunning)
{
System.out.println("TCP server starting: IP address "
+ InetAddress.getLocalHost().toString() + " port " + receivePort );
serverSocket = new ServerSocket(receivePort);
socket = serverSocket.accept(); // Wait for client to connect.
System.out.println("TCP Client connect from IP address " + socket.getInetAddress()
+ " port " + socket.getPort());
br = ( ( socket.getInputStream() ) );
pw = ( socket.getOutputStream() );
while(threadRunning)
try
{
// read TCP packet into byte array and convert to a string
byte data[]=new byte[10000];
int length = br.read(data);
String s = new String(data, 0, length); // create a string from the data
System.out.println("\nTCP data '" + s +"'");
// find start of data, e.g. *HELLO*
int hello = s.indexOf("*HELLO*");
// and extract the hexadecimal string for sensors 2 and 3
String sensor2 = s.substring(hello+19, hello+23);
String sensor3 = s.substring(hello+24, hello+28);
System.out.println("sensor 2 0x" + sensor2 + " sensor 3 0x" + sensor3 );
// convert the hexadecimal values to integer and display
System.out.println("sensor 2 " + Integer.parseInt(sensor2, 16)
+ " sensor 3 " + Integer.parseInt(sensor3, 16) );
}
catch (Exception se) {System.err.println("error " + se); break;}
serverSocket.close();
}
}
catch (Exception se) {System.err.println("run() " + se); }
System.exit(1); // exit on failure
}
public static void main(String args[])
{
int receivePort=80;//10000;//999;//20000; // port to receive
TCPserver frameInput = new TCPserver(receivePort); // create server to receive messages
frameInput.start(); // and start it
System.out.println("ready to receive TCP from socket " + receivePort);
}
}
*HELLO*0D11000000003DFC000C0000000000000000 HTTP/1.0
Host: dns1
String sensor2 = s.substring(hello+19, hello+23);
String sensor3 = s.substring(hello+24, hello+28);
System.out.println("sensor 2 " + Integer.parseInt(sensor2, 16)
+ " sensor 3 " + Integer.parseInt(sensor3, 16) );
yes, set up the TCP as the example in earlier post, e.g.So if i want to send just hello messsage it is possible to do this
- - - Updated - - -
because in my case i haven't any sensor and i want just to test the transmission of a hello message
set ip h 192.168.1.65 set TCP server IP
AOK
<4.00> set ip r 80 set TCP server port for HTTP
AOK
<4.00> set i p 18 enable TCP and HTTP client mode
AOK
<4.00> set o f 7 append sensor data to HTTP
AOK
<4.00> set b i 7 set broadcast 1 packet every 8 seconds
AOK
<4.00> open open TCP client connection
<4.00> *OPEN*
yesin your case
192.168.1.65 is the adress of the receiver (TCP Server )?
192.168.1.64 is the ip of your wireless network?
I had problems connecting to my main WiFi router which was a distance of about 10 metres from the RN171 board - I think the power output of the RN171 was too low for reliable communicationi have a problem with my rn171 because sometimes it dont' succed to detect and join the wireless network ; is it the problem in all RN171 or it is possible to solve this problem
thanks in advance
in my case I only have sensors 2 and 3 connected so my setting for the set q sensor command wasin my case i have receives this data witout using any sensor
*HELLO*1D17CF29CF2907F33D2507B907FE307B3094 HTTP/1.0
Host: dns1
so it is present the transmssion of hello message and
1D17CF29CF2907F33D2507B907FE307B3094 present the data in sensor
thanks in advace
set q s 0x0c sample sensors 2 and 3
TCP data '*HELLO*0D11000000003DFC000C0000000000000000 HTTP/1.0
Host: dns1
set q s 0xFF sample all sensors
*HELLO*1D17CF29CF2907F33D2507B907FE307B3094 HTTP/1.0
Host: dns1
it looks like the TCP connection is opening OK and then immediatly closingi have a problem just in the Tcp mode ; when i configure with cable it work and when i put the battry it don't work and it display me this messgae in tera term
<4.00> open
<4.00> *OPEN**CLOS**CLOS*
another question about RN171; the default of RN171 is about the connexion in wifi and the detection of an acess point
the rn171 don't reset and the tcp server play me error connection
so when i m trying with putting the battery and the cable in same time and when the configuration seting is finish i discnnect the cable:; and it work
if i put the cable and battery in the same time it work via the baterry or with the cable
another question about RN171-EK;
i would like to know if i put the battery and the usb cable in the same time, so the RN171 will take power via the PC or via the2 battery
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?