Go Down

Topic: Ethernet Sheild and GSM router (Read 4054 times) previous topic - next topic

gibbon

Oct 08, 2012, 10:12 am Last Edit: Oct 08, 2012, 11:57 am by gibbon Reason: 1
Hi, within my job i use industrial GSM routers (a GSM modem with thernet port) to connect computers on site to the internet and as far as my understanding of them, there a router with a simcard and act like any other router?

So..i have my ethernet shield on my arduino and i have set it to connect to a server i have, this works fine when i share my computers ethernet port and loop the arduino into there (so its using my internet) when i plug it into the GSM router however, it cannot make a connection, yet throws no ethernet connection errors.

in the router log though i do see this:
  DHCPDISCOVER(lan0) de:ad:be:ef:fe:ed
info   Oct 6 13:27:06   dnsmasq[782]   DHCPOFFER(lan0) 192.168.104.146 de:ad:be:ef:fe:ed
info   Oct 6 13:27:06   dnsmasq[782]   DHCPDISCOVER(lan0) de:ad:be:ef:fe:ed
info   Oct 6 13:27:06   dnsmasq[782]   DHCPOFFER(lan0) 192.168.104.146 de:ad:be:ef:fe:ed
info   Oct 6 13:27:06   dnsmasq[782]   DHCPREQUEST(lan0) 192.168.104.146 de:ad:be:ef:fe:ed
info   Oct 6 13:27:06   dnsmasq[782]   DHCPACK(lan0) 192.168.104.146 de:ad:be:ef:fe:ed WIZnetEFFEED
info   Oct 6 13:31:23   kernel   lan0: link down
info   Oct 6 13:31:25   kernel   lan0: link up, 100Mbps, full-duplex, lpa 0x41E1
info   Oct 6 13:31:30   dnsmasq[782]   DHCPDISCOVER(lan0) de:ad:be:ef:fe:ed
info   Oct 6 13:31:30   dnsmasq[782]   DHCPOFFER(lan0) 192.168.104.146 de:ad:be:ef:fe:ed
info   Oct 6 13:31:30   dnsmasq[782]   DHCPREQUEST(lan0) 192.168.104.146 de:ad:be:ef:fe:ed
info   Oct 6 13:31:30   dnsmasq[782]   DHCPACK(lan0) 192.168.104.146 de:ad:be:ef:fe:ed WIZnetEFFEED
info   Oct 6 13:32:59   kernel   lan0: link down
info   Oct 6 13:33:02   kernel   lan0: link up, 100Mbps, full-duplex, lpa 0x41E1

This repeats and repeats, i assume WIZnetEFFEED is the ethernet shield?

Does anyone know what is happeneing above and to why it wont connect?

The GSm router does work, and i can plug it into my computer and browse sites using the GSM.

Note: Since playing ive come to the conclusion that the above is fine... and therefore is having no issue to why i can not connect to the server, could this simply be caused by the delay being over GSM?

Thanks
Andy

pylon

Quote
could this simply be caused by the delay being over GSM?


That depends on the used software. Show us your sketch, maybe you have an issue there.

gibbon

Hi, no probs this is the code i have, its probably as basic as it can get as its taken from examples.

Im using the pusherapp library that can be found here:
https://github.com/krohling/ArduinoPusherClient

Ive also tried using just the websocket library & my own server but get the same results:
https://github.com/krohling/ArduinoWebsocketClient

This is my code, this works when using a normal insternet but not over my GSM router, yet my GSM router works fine and ive tried using my browser to make a connection using the GSM and that too works fine, but put the arduino and GSM together and its a no go.

The code:
Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
#include <PusherClient.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
//byte ip[] = {192,168,2,1};
//byte gateway[] = {192,168,2,1};
//byte subnet[] = {255,255,255,0};

PusherClient client;

void setup() {

 Serial.begin(9600);
  Ethernet.begin(mac);

 Serial.print("My IP address: ");
 for (byte thisByte = 0; thisByte < 4; thisByte++) {
   // print the value of each byte of the IP address:
   Serial.print(Ethernet.localIP()[thisByte], DEC);
   Serial.print(".");
 }
   Serial.println();
   delay(1000);
   
   Serial.print("Connecting to server... ");
   Serial.println();
   while(client.connect("8bce0224d7dae3e8e75e") == 0){
     Serial.println("Cannont Connect, retyring after 2 seconds...");
     delay(2000);
   }
   
   //connected
   Serial.println("connected");
   client.bind("forward", moveForward);
   client.bind("backward", moveBackward);
   client.subscribe("my_channel");
 
 
}

void loop() {
 if (client.connected()) {
   client.monitor();
 }
 else {

 }
}

void moveForward(String data) {
Serial.println("forward");
}

void moveBackward(String data) {
Serial.println("backward");
}



Many thanks
Andy

pylon

In your code there are Serial.print() statements, what output do you get, where does it stop?

Do you get an IP address?

Have you tried a simpler example from Ethernet.h examples, like WebClient? Connecting to a host like www.google.com is a much better test than to a service which may be down while you're trying to connect or may have decided to not answer requests from certain networks.

gibbon

Hi pylon, yes i get an IP and it tells me its tryign to connect but then obviously doesnt for whatever reason and prints "cannot connect, retrying in 2 seconds..." and it keeps doing this, as you can see in the while loop.

I have tried a simple one and it can connect to www.google.com and can print the get request in the serial monitor, so the connection through the GSM router works. But so does the client to server as, if I plug the arduino into my normal internet it connects to the websocket server fine?

I have also wrote a simple script in js that connects to the server and attatched the GSM to laptop (instead of the arduino) and i can connect to the server fine, its only when the arduino tries to connect to the server using the GSM router that i cannot make a connection?

Any ideas?

Thanks
Andy

pylon

Have you tried doing the same connection (to the websocket server) on your laptop using the telnet command? I guess it's not an Arduino problem but one on the network, somewhere between your GSM router and the server.

gibbon

Quote
Have you tried doing the same connection (to the websocket server) on your laptop using the telnet command?


Yes and it works fine.

Quote
I guess it's not an Arduino problem but one on the network, somewhere between your GSM router and the server.


But i can plug my laptop into the GSM router and connect to the server fine? Unplug laptop, plug in arduino and cant connect.

thanks
Andy

pylon

The error is in the library you're using:

Code: [Select]
    while(_client.available() == 0 && attempts < maxAttempts)
    {
        delay(100);
        attempts++;
    }
   
    while((line = readLine()) != "") {
        handshake += line + '\n';
    }


The code is waiting for up to 30 seconds for one character to arrive but then the whole answer has to be there completely. I'd guess that the GSM modem is splitting the packets into smaller packets and the library code isn't prepared for that.

gibbon

Ahh ok, ive looked at this code for while thinking this is where the problem (if any) must lie.

I will give it ago despite my C++ not being to good, but i have to ask, do you have any idea how to impliment a workaround to wait for all packets before proceeding?

Thanks
Andy

pylon

Although this is an ugly hack, it might be enough for your needs:

Code: [Select]
    while(_client.available() < 14 && attempts < maxAttempts)
    {
        delay(100);
        attempts++;
    }
   
    while((line = readLine()) != "") {
        handshake += line + '\n';
    }


This way you're waiting for at least the string to be arrived you're testing for afterwards.

BTW: the author of the library did a lot of work to move the constant strings to the flash memory (PROGMEM) but then uses the String class which wastes more memory than he saved with the first action but making the code much more complex.

SurferTim

#10
Oct 09, 2012, 03:53 pm Last Edit: Oct 09, 2012, 03:59 pm by SurferTim Reason: 1
Why don't you wait for the server to close the connection? That is the signal it is finished sending packets. If it is like the ethernet library, you should be able to use this. It should wait ten seconds for a packet before aborting the connection.
Code: [Select]
while(_client.connected()) {
 while(_client.available()) {
   // if a packet arrives, reset the attempts counter
   attempts = 0;
   Serial.write(_client.read());
 }
 // increment counter and wait 1ms
 attempts++;
 delay(1);

 // if the counter has reached the timeout value, close the connection
 if(attempts > 10000) _client.stop();
}
// close the connection on your end after the server closes the connection
// This would be the second stop if there is a timeout,
// but does not affect the ethernet shield.
_client.stop();

My apology in advance for errors or typos.

edit: I had the wrong delay value. It is now corrected.

gibbon

HI pylon, ive tried doing what you did, but unfortunatly it hasnt wroked as of yet. Where di you pluck the 14 from? (just trying to understand?)

SurferTim is that code a modification of the c++ library? (which is what im trying to do)

Thanks
Andy

SurferTim

Look here. Is this the code you are using?
https://github.com/krohling/ArduinoWebsocketClient/blob/master/WebSocketClient.cpp
All those functions are available with that library also. This is pretty standard TCP stuff. The transport should be transparent.

gibbon

#13
Oct 09, 2012, 04:30 pm Last Edit: Oct 09, 2012, 04:32 pm by gibbon Reason: 1
Yes that is what im using, but its not working when used with a GSM router and we think this is becasue the GSM might be splitting up packets and the library therefore isnt interpreting the handshake correctly.

Andy


SurferTim

The code I posted above does not matter how many packets the response is sent in. It could be one packet with a thousand characters, or a thousand packets with one character. It waits for the server to close the connection. That is why the "while(client.connected())" loop.

Go Up