Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

wireless communication with PIC24f and MRF24WB0MA

Status
Not open for further replies.
yes, you don't need a second RN171
you can connect to your local Wireless network and run a server on a PC to receive data, e.g. the code the UDP server
Code:
// simple UDP server waiting for datagrams and extracting a string

import java.io.*;
import java.util.*;
import java.net.*;

public class UDPserver extends Thread
{
public static void main(String args[])
{
        int receivePort=999;                                                                                        // port to receive datagrams from
        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
        try
              {
              // 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
                 String s = new String(data, 0, dp.getLength());         // create a string from the data
                 System.out.println("\nFrom IP " + dp.getAddress() + " UDP string received " + s + "\n");
                }
              }
        catch (IOException se) {System.err.println("error " + se);}
        System.exit(1);                                                 // exit on failure
}
}
hello plz if i want to se TCP protocol can you please give me the program java of TCP
thanks in advance
 

hello plz if i want to se TCP protocol can you please give me the program java of TCP
thanks in advance
if you do a web search for java TCP client/server you will find examples

this is a server I use
Code:
// 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;
        ObjectInputStream br=null;
        ObjectOutputStream 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;
          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  = new ObjectInputStream( ( socket.getInputStream() ) );
                  pw = new ObjectOutputStream( socket.getOutputStream() );
                  while(threadRunning)
                    try
                    {
                      String code = (String) br.readObject();
                      System.out.println( "Server received string: '" + 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
	{
	// get machine IP address - two methods
	Socket soc = new Socket("192.168.1.1", 80);
	System.out.println("TCP server on IP address " + soc.getLocalAddress().getHostAddress() + " port " + receivePort);
	soc.close();
	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, i'm trying this code to test tcp cnnection and with this configuration in teraterm

CMD
scan
<4.00>
SCAN:Found 1
01,01,-72,02,1104,14,00,00:1d:20:db:0b:46,Wifi
END:
set wlan ssid Wifi
AOK
<4.00> set wlan pass passwir
AOK
<4.00> join
Auto-Assoc Wifi chan=1 mode=WPA2 SCAN OK
<4.00> Joining Wifi now..
Associated!
DHCP: Start
DHCP in 1704ms, lease=86400s
IF=UP
DHCP=ON
IP=192.168.1.7:2000
NM=255.255.255.0
GW=192.168.1.1
Listen on 2000
set ip host 192.168.1.4
AOK
<4.00> set ip remote 999
AOK
<4.00> set ip local 2000
AOK
<4.00> exit
EXIT

but i dont receive any message in jaava
i have a question about the port number of java in java code(999) don't exist in java code
and it is possible to send any analogik information every 10s (set sys autoconn 10) with tcp protocol plz
thnkks n advance
 

the Java receive port is 20000 set in main()
Code:
     int receivePort=20000;                                 // port to receive datagrams on
and passed to the TCPserver method as a parameter
Code:
        TCPserver frameInput = new TCPserver(receivePort);    // create server to receive messages
this is the client
Code:
// TCP client which sends a message to a server 

import java.io.*;
import java.util.*;
import java.net.*;

public class TCPclient
{
private final static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));


public static void main(String args[])
{
   System.out.println("enter message to send to server");
   String remoteIPaddress="127.0.0.1";
   int remotePort=20000;
   try
       {
        Socket socket1 = new Socket( remoteIPaddress, remotePort );   
        ObjectOutputStream objOut = new ObjectOutputStream( socket1.getOutputStream() );
        System.out.println("Server contacted OK , enter text to send " );
        while(true)
            {
             String s = in.readLine();
             objOut.writeObject(s);         // send message
            }  
        }
    catch (IOException e) {System.err.println("TCP client error " +  e); }
 }

}
when run the server gives
Code:
Run program: java -Djava.compiler=NONE -classpath "c:\temp\;." TCPserver
TCP server on IP address 192.168.1.13 port 20000
TCP server on IP address 169.254.57.62 port 20000
TCP server starting: IP address xxxx/169.254.57.62 port 20000
Client connect from IP address /127.0.0.1 port 50540
Server received string: 'hallo'
Server received string: 'bye'
and the client
Code:
Run program: java -Djava.compiler=NONE -classpath "c:\temp\;." TCPclient
enter message to send to server
Server contacted OK , enter text to send 
hallo
bye
 
  • Like
Reactions: ings

    ings

    Points: 2
    Helpful Answer Positive Rating
so in case of communication between rn171 and a PC via TCP protocol (AP mode) and when i want tht rn171 is the emitter, i will program the tcp as tcp server and the configuration of rn171 in TeraTerm it is :
Code:
CMD
scan
<4.00>
SCAN:Found 1
01,01,-72,02,1104,14,00,00:1d:20:db:0b:46,Wifi
END:
set wlan ssid Wifi
AOK
<4.00> set wlan pass passwir
AOK
<4.00> join
Auto-Assoc Wifi chan=1 mode=WPA2 SCAN OK
<4.00> Joining Wifi now..
Associated!
DHCP: Start
DHCP in 1704ms, lease=86400s
IF=UP
DHCP=ON
IP=192.168.1.7:2000
NM=255.255.255.0
GW=192.168.1.1
Listen on 2000
set ip host 192.168.1.4
AOK
<4.00> set ip remote 999
AOK
<4.00> set ip local 2000
AOK
<4.00> exit
EXIT
thanks in advance
 

run the TCP server on the PC and use the RN171 as the client
 
  • Like
Reactions: ings

    ings

    Points: 2
    Helpful Answer Positive Rating
my rn171-Ek sometime can't detect the wifi and when i succeded to detect the wifi and conecting to the wifi , it disconnect and dsplay me lost AP or disconect from wifi like this
Code:
CMD
scan
<4.00>
SCAN:Found 1
01,11,-76,02,3104,54,40,00:25:53:14:aa:e2,wifi1
END:
set wlan ssid wifi1
AOK
<4.00> set wlan pass passw
AOK
<4.00> join
Auto-Assoc wifi1 chan=11 mode=WPA2 SCAN OK
<4.00> Joining wifi1 now..
Disconn from wifi1,AUTH-ERR
join
Auto-Assoc fatma1 chan=0 mode=NONE FAILED
<4.00> set wlan ssid wifi1
AOK
<4.00> set wlan pass passw
AOK
<4.00> join
Auto-Assoc wifi1 chan=0 mode=NONE FAILED
<4.00> scan
<4.00>
SCAN:Found 0
END:
scan
<4.00>
SCAN:Found 0
END:
scan
<4.00>
SCAN:Found 0
END:
can you help me to knowing the cause of the problem. is it the problem in all rn171 card?
thanks in advance
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top