[SOLVED] GSM with Xbee for cloud

Hello everyone,

Im making a project, I am using UBIDOTS to display the status online. I am using an Arduino mega and Arduino gsm shield. Using the example code given by UBIDOTS, I have managed to send some integer values and this works perfectly however I cannot get my Xbee code integrated into the gsm code. The Xbee code is receiving data from a reedswitch and sending it wirelessly to the other xbee. Below is the code for the xbee. When the data is uploaded onto the cloud I need it to be in characters. Thanks in advance

Xbee coding:

int readValue = 0;
int x;
void setup() {
 Serial.begin(9600); 
}

void loop() {
  if(Serial.available() > 13) {
    //Serial.println(Serial.read(), HEX);
    for(int i=0; i<14; i++) {
      x =Serial.read();
    //  Serial.print("i= ");
    //  Serial.print(i);
    //  Serial.print("  ");
     // Serial.print(x,HEX);
     // Serial.print("  ");
        if (i == 12) 
      { if (x == 0)   
    {Serial.println(" LOW");}
                           
                         else {Serial.println(" HIGH"); } }
   
  }
}
}

GSM code by UBIDOTS:

 // libraries
        #include <GSM.h>

        // PIN Number
        #define PINNUMBER ""

        // APN data
        #define GPRS_APN       "sm2ms.movilforum.es" // replace with your GPRS APN
        #define GPRS_LOGIN     ""    // replace with your GPRS login
        #define GPRS_PASSWORD  "" // replace with your GPRS password

        // initialize the library instance
        GSMClient client;
        GPRS gprs;
        GSM gsmAccess;
        uint16_t reset = 0;


        String idvariable = "565c7ce5762542029c2b9c47";   // replace with your Ubidots Variable ID
        String token = "WIsjN9xzR8s8p2lwHa4VK7Eiu8phegFtlFBCCwtQiC2RITN4XcKWjIWAiR7U";  // replace with your Ubidots token

        void setup()
        {
          // initialize serial communications and wait for port to open:
          Serial.begin(9600);
          while (!Serial) {
            ; // wait for serial port to connect. Needed for Leonardo only
          }

          Serial.println("Starting Arduino web client.");
          // connection state
          boolean notConnected = true;

          // After starting the modem with GSM.begin()
          // attach the shield to the GPRS network with the APN, login and password
          while (notConnected)
          {
            if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
                (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
              notConnected = false;
            else
            {
              Serial.println("Not connected");
              delay(1000);
            }
          }
        }

        void loop()
        {
          int value = 9860;
          if(save_value(value))
          {
          }
          else
          {
            reset++;
            if (reset == 10)
            {
              asm volatile ("  jmp 0");    // reset the Arduino board if the data transmission fail
            }
          }

          // if the server's disconnected, stop the client:
          if (!client.available() && !client.connected())
          {
            Serial.println();
            Serial.println("disconnecting.");
            client.stop();

            // do nothing forevermore:

          } 
         
        }
        boolean save_value(int value)
        {
          Serial.println("connecting...");

          int num=0;
          String var = "{\"value\":"+ String(value) + "}";
          num = var.length();
          // if you get a connection, report back via serial:
          if (client.connect("things.ubidots.com", 80))
          {
            Serial.println("connected");
            // Make a HTTP request:
            client.print("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1\nContent-Type: application/json\nContent-Length: "+String(num)+"\nX-Auth-Token: "+token+"\nHost: things.ubidots.com\n\n");
            client.println(var);
            client.println();

          }
          else
          {
            // if you didn't get a connection to the server:
            Serial.println("connection failed");
            return false;
          }
            while (client.available())
          {

            char c = client.read();
            Serial.print(c);
          }
        }

Hi @Hiran1302

It seems your code outputs “x” as the variable with the data to be sent. Put this data (make sure to convert it to integer), into the save_value function:

save_value(x);