Question

I'm trying to send arduino sensor data to a server using a GPRS shield (sim900 shield from geeetech http://www.geeetech.com/wiki/index.php/Arduino_GPRS_Shield). I have this particular set up because the data will be updated to a website and the device will be roaming. I can't use http://www.cosm.org because to the best of my knowledge that only updates every 15 minutes, I need to update about every 5-10 seconds.

In order to connect I tried the code below to form UDP connection but it does not get sent through to the receiving IP and port. I dont know why, no errors occur on the arduino side.

///connect
void connectUDP()
{
 mySerial.println("AT+CSTT=\"APN\"");
 delay(3000);
 ShowSerialData();
 mySerial.println("AT+CIICR");
 delay(3000);
 ShowSerialData();
 mySerial.println("AT+CIFSR");
 delay(3000);
 ShowSerialData();
 mySerial.println("AT+CIPSTART=\"UDP\",\"SERVER IP\",\"SERVER PORT\"");
 delay(3000);
 ShowSerialData();
 mySerial.println();

}


///send udp packet to server 
void sendUDP()
{
 for(int x = 0; x < 30; x++){
   mySerial.println("AT+CIPSEND"); 
   delay(100);
   ShowSerialData();
   mySerial.println("\"hello world\"");
   delay(100);
   ShowSerialData();
   mySerial.println((char)26);
   delay(1000);
   ShowSerialData();
 }
 mySerial.println();
 //ShowSerialData();
}

The server side is as follows (written in python):

import SocketServer

PORTNO = 14

class handler(SocketServer.DatagramRequestHandler):
    def handle(self):
        newmsg = self.rfile.readline().rstrip()
    print (newmsg)
        self.wfile.write(self.server.oldmsg)
        self.server.oldmsg = newmsg

s = SocketServer.UDPServer(('',PORTNO), handler)
print "Awaiting UDP messages on port %d" % PORTNO
s.oldmsg = "This is the starting message."
s.serve_forever()

I can see a possible solution might be to change it to a TCP connection, but I don't know how to do that...

Was it helpful?

Solution

First of all: never, never ever use delay instead of proper waiting by parsing the actual response given by the modem. See this answer for more details, including the point about waiting for "\r\n> " before sending data, which AT+CIPSEND apparently shares behaviour with AT+CMGS.

Then when you have fixed your AT command handling (see this answer for some hints), change SERVER IP and SERVER PORT to something that is open/not firewalled on your own PC (verify by checking at ShieldsUP). Run Wireshark while running the AT commands and verify that you receive the corresponding traffic. If everything is working as expected up till this point, then the problem appears to be with the server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top