save IP from a Sim808 as int

hi,
i’m trying to put the received IP from my provider (SIM808 board) in to en int.
i’m using a Mega 256 board en the SIM808 is atteched at Serial1.
atteched you finfd 1 of the many things that i tryed.
can you thell me where i did go wrong?

AT_IP.ino (2.06 KB)

Looks like you are only reading the first byte of what you are inputting from the PC.

Paul

On the Mega, an int is sixteen bits.
An IP address is at least thirty-two bits.

Please, just POST the code, don't attach it.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

hi,

here is my code.
can i better write it in to a char?

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "inetGSM.h"
//#include "sms.h"
//#include "call.h"

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to communicate with SIM900 through AT commands.

InetGSM inet;
//CallGSM call;
//SMSGSM sms;

int numdata;
char inSerial[40];
int i=0;
int IP=0;


void setup()
{
     //Serial connection.
     Serial.begin(9600);
     Serial.println("GSM Shield testing.");
     //Start configuration of shield with baudrate.
     //For http uses is raccomanded to use 4800 or slower.
     if (gsm.begin(9600))
          Serial.println("\nstatus=READY");
     else Serial.println("\nstatus=IDLE");
     inet.attachGPRS("telenetwap.be", "", "");
delay(200);
 gsm.SimpleWriteln("AT+CIFSR");
 
     if(Serial.available() >0)  {Serial1.write(Serial.read()); } 
     if (Serial1.available() >0) {Serial.write(Serial1.read());}
     IP= Serial1.read();
      Serial.println("test");
     Serial.println(IP);
};

void loop()
{
     //Read for new byte on serial hardware,
     //and write them on NewSoftSerial.
     serialhwread();
     //Read for new byte on NewSoftSerial.
     serialswread();
};

void serialhwread()
{
     i=0;
     if (Serial.available() > 0) {
          while (Serial.available() > 0) {
               inSerial[i]=(Serial.read());
               delay(10);
               i++;
          }

          inSerial[i]='\0';
          if(!strcmp(inSerial,"/END")) {
               Serial.println("_");
               inSerial[0]=0x1a;
               inSerial[1]='\0';
               gsm.SimpleWriteln(inSerial);
          }
          //Send a saved AT command using serial port.
          if(!strcmp(inSerial,"TEST")) {
               Serial.println("SIGNAL QUALITY");
               gsm.SimpleWriteln("AT+CSQ");
          } else {
               Serial.println(inSerial);
               gsm.SimpleWriteln(inSerial);
          }
          inSerial[0]='\0';
     }
}

void serialswread()
{
     gsm.SimpleRead();
}

greets