General

How can the WiFi shield V2.1 send data to PC

userHead Mjp 2012-07-16 06:33:36 13501 Views6 Replies
Dear all,
My final year project is to send the sensor data from Arduino to PC through WiFi and PC would send command back to arduino to remote control it. I just bought the DFRobot WiFi shield V2.1 and hope it can help me relise the WiFi communication (transmission).

I have configured this shield successfully as referred to the tutorial. However, I am not sure if I set the server mode and port number on the WiFi shield, is that mean I have already created a server socket on the Arduino side? Instead of using Hyperterminal or Putty to set the destination IP and port number, do I need to create a client socket (JAVA) on the PC to get/send the data from/to Arduino?

As a beginner of Arduino project, I would be very grateful if someone can give me some suggestions on how to undertake my project.  :)
2012-07-17 17:33:49 [quote="Hector"]
Hi,


I am not familiar with the WiFly's library. I don't know what features it has, but I can't imagine why you would need a library for the wifi shield. It simply does serial communication over wifi.


You might also want to try processing or python rather than JAVA. I think either of those solutions will have some readily available code for listening to a port for incoming data.
[/quote]

Thank u Hector, for your suggestions! I thought even though I have configured the wifi shield, I still need to specify the network information (SSID, Gateway...) and port number. :( It seems Im wrong.

I will learn how to use processing and try to use it. Thank u again for your help!

Kind regards,
Mjp
userHeadPic Mjp
2012-07-17 10:54:26 Hi,


I am not familiar with the WiFly's library. I don't know what features it has, but I can't imagine why you would need a library for the wifi shield. It simply does serial communication over wifi.


You might also want to try processing or python rather than JAVA. I think either of those solutions will have some readily available code for listening to a port for incoming data.

userHeadPic Hector
2012-07-17 08:11:24 [quote="Hector"]
Hi MJP,


were you able to get a response in PuTTy?


its the same principal for your application. I have not used Mathematica. But basically you need to tell the Arduino to wait for a certain entry, or what ever you will use as a trigger to send serial data out.


So, this way it will send the data the same way it sent the "on/off" data to the Putty terminal.


The wifi shield basically broadcasts the data from the arduino's serial port over wifi. You need to get Mathematica to "listen" on the IP address and port for incoming information.
[/quote]

Thank u again, Hector!

I can get response from Putty. The difficult thing is to get Mathematica 'listen' for the broadcast data as u explained. It cannot create a TCP/IP socket on Mathematica. Im thinking about two ways. One is using Java to create a client socket and listen for the incoming data. Then, program on Mathematica to extract data from Java. However, It seems only one Java client socket program, it would not get connected with Arduino. Another way is supposed to let Arduino send data to a web server that connect to MySQL database. Therefore, the Mathematica can extract data from the database.

Sorry about my poor English and I hope u could understand. Do u have any suggestions after reading my ideas?

P.S. I searched there is a WiFi library provided by Sparkfun company for their Wifly shield. This shield also use the same pins for the connection. Do u know whether the WiFi library also compatible with the DFRobot WiFi shield V2.1?

Kind regards,
Mjp
userHeadPic Mjp
2012-07-16 17:40:42 Hi MJP,


were you able to get a response in PuTTy?


its the same principal for your application. I have not used Mathematica. But basically you need to tell the Arduino to wait for a certain entry, or what ever you will use as a trigger to send serial data out.


So, this way it will send the data the same way it sent the "on/off" data to the Putty terminal.


The wifi shield basically broadcasts the data from the arduino's serial port over wifi. You need to get Mathematica to "listen" on the IP address and port for incoming information.
userHeadPic Hector
2012-07-16 17:05:11 [quote="Hector"]


Now open a terminal. You can use PuTTy, or if you have a Windows XP machine you can use the Hyperterminal included. and connect to the WiFi shield’s IP address. Don’t forget to indicate the server port. In our example we are using port “5000?

Once connected to the WiFi shield you should be able to control the Arduino’s onboard LED by pressing 1 or 0. You should also get some feedback in the terminal.
[/quote]

Hi Hector,
Thank u very much for your help. I have done this LED test. My problem is that I have to use Mathematica software on PC to extract data from Arduino not from Putty nor Hyperterminal. Could u please another example that how can I get data from Arduino server side?

Kind regards,
Mjp
userHeadPic Mjp
2012-07-16 11:48:22 Hi MJP,


I will work on a tutorial this week.


Here is a bit from the old wifi shield, but it explains a bit of your question:


The “Mode” setting depends on you but, we recommend “server” as it makes it easier to connect to. This setting indicates weather the WiFi shield will wait for a connection from another IP address (server mode), or if it will try to connect to a specific IP address you give it (Client mode). You can use the “Mixed mode” but will only be able to connect to it from one place at a time. You do not need to change the server port but take note of its value. You will need it later to connect to the Serial “server”. The “baudrate” can be what ever you like it to be, just make sure its the same in your WiFi shield settings, and your Arduino Sketch.
Once you are done making the necessary changes “save”. You are now done with the WiFi shield settings.

Code: Select all
void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(57600);
  delay(100);
  Serial.println("Press any key to continue");
  while(Serial.available()==0);
  Serial.println("  Lets test the DFRobot WiFi Shield");
  Serial.println("Press 1 to light the LED, and 0 to turn it off");
  Serial.println("Entery: ");
  digitalWrite(13, HIGH);
}

void loop() {

  if (Serial.available()){

    char input = Serial.read();
    switch (input){
    case '1':
      digitalWrite(13, HIGH);
      Serial.println("ON");
      delay(500);
      break;
    case '0':
      digitalWrite(13, LOW);
      Serial.println("OFF");
      delay(500);
      break;
    }
  }
}
Now open a terminal. You can use PuTTy, or if you have a Windows XP machine you can use the Hyperterminal included. and connect to the WiFi shield’s IP address. Don’t forget to indicate the server port. In our example we are using port “5000?

Once connected to the WiFi shield you should be able to control the Arduino’s onboard LED by pressing 1 or 0. You should also get some feedback in the terminal.
userHeadPic Hector