Libelium is offering new technical support channels, to contact with de Technical Support team to solve any issue our doubt please contact with your sales agent or visit our contact site



Post a new topicPost a reply Page 1 of 1   [ 2 posts ]
Author Message
 Post subject: Problema con subida de datos a Xively
PostPosted: Thu Jun 29, 2017 2:51 pm 

Joined: Wed Jun 07, 2017 6:05 pm
Posts: 2
Buenos dias, Tengo un problema a la hora de subir datos a Xively con el modulo SIM908. Ya no se si es problema del modulo o del codigo.

Code:
int8_t answer;
int onModulePin= 2;

char aux_str[50];

String humedad="0";

String TCP_message ="{\"method\": \"put\",\"resource\": \"/feeds/1827207496/\",\"params\": {},\"headers\": {\"X-ApiKey\":  \"f1qLvQ1Piw1FPJbUVpT7qkLUrlyHOjbPjlQSLwGcMGmHxfuD\"},\"body\": {\"version\": \"1.0.0\",\"datastreams\": [{\"id\": \"Humedad\",\"current_value\": \"" + humedad + "\"}]}}";

void setup(){
   
    pinMode(onModulePin, OUTPUT);
    Serial.begin(115200);   
   
    Serial.println("Starting...");
    power_on();
   
    delay(3000);
   
    // sets the PIN code
    sendATcommand2("AT+CPIN=3765", "OK", "ERROR", 2000);
   
    delay(3000);
   
    while (sendATcommand2("AT+CREG?", "+CREG: 0,1", "+CREG: 0,5", 1000)==0);
   
}
void loop(){

  humedad = "7";

  TCP_message ="{\"method\": \"put\",\"resource\": \"/feeds/1827207496/\",\"params\": {},\"headers\": {\"X-ApiKey\":  \"f1qLvQ1Piw1FPJbUVpT7qkLUrlyHOjbPjlQSLwGcMGmHxfuD\"},\"body\": {\"version\": \"1.0.0\",\"datastreams\": [{\"id\": \"Humedad\",\"current_value\": \"" + humedad + "\"}]}}";
   
  char message_TCP [300];
  TCP_message.toCharArray(message_TCP, 300); // converting TCP_message to char inorder for it to pass through AT command

  if(sendATcommand2("AT+CIPMUX=0","OK","ERROR",1000)==1)
  {
    while(sendATcommand2("AT+CIPSTATUS","INITIAL","",500)==0);
    delay(5000);

    if(sendATcommand2("AT+CSTT=\"gprs-service.com\",\"\",\"\"","OK","ERROR",30000)==1)
    {
      while(sendATcommand2("AT+CIPSTATUS","START","",500)==0);
      delay(5000);

      if(sendATcommand2("AT+CIICR","OK","ERROR",30000)==1)
      {
        while(sendATcommand2("AT+CIPSTATUS","GPRSACT","",500)==0);
        delay(5000);

        if(sendATcommand2("AT+CIFSR",".","ERROR",10000)==1)
        {
          while(sendATcommand2("AT+CIPSTATUS","IP STATUS","",500)==0);
          delay(5000);
          Serial.println("Openning TCP");

          if(sendATcommand2("AT+CIPSTART=\"TCP\",\"api.xively.com\",\"8081\"","CONNECT OK", "CONNECT FAIL", 30000)==1)
          {
            Serial.println("Konektatua");

            sprintf(aux_str,"AT+CIPSEND=%d", strlen(message_TCP));
            if(sendATcommand2(aux_str,">","ERROR",10000)==1)
          {
          sendATcommand2(message_TCP,"","ERROR",20000);
          Serial.println("Mensaje mandado!");
        }
        sendATcommand2("AT+CIPCLOSE","CLOSE OK","ERROR",10000);
          }
        else
        {
          Serial.println("Errorea konexioa irekitzen");
        }
      }
      else
      {
        Serial.println("Errorea IP helbidea lortzen");
      }
    }
    else
    {
      Serial.println("Errorea hari gabeko konexioa irekitzen");
    }
  }
  else
  {
    Serial.println("Errorea APN-a konfigurazioarekin");
  }
}
else
{
  Serial.println("Errorea konexioa ezartzen");
}
sendATcommand2("AT+CIPSHUT","OK","ERROR",10000);

delay (4000);

}
         
     
   
 
 
void power_on(){

    uint8_t answer=0;
   
    // checks if the module is started
    answer = sendATcommand2("AT", "OK", "OK", 2000);
    if (answer == 0)
    {
        // power on pulse
        digitalWrite(onModulePin,HIGH);
        delay(3000);
        digitalWrite(onModulePin,LOW);
   
        // waits for an answer from the module
        while(answer == 0){   
            // Send AT every two seconds and wait for the answer
            answer = sendATcommand2("AT", "OK", "OK", 2000);   
        }
    }   
}

int8_t sendATcommand2(char* ATcommand, char* expected_answer1,
        char* expected_answer2, unsigned int timeout)
{

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialize the string
   
    delay(100);
   
    while( Serial.available() > 0) Serial.read();    // Clean the input buffer
   
    Serial.println(ATcommand);    // Send the AT command


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{

        if(Serial.available() != 0){   
            response[x] = Serial.read();
            x++;
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer1) != NULL)   
            {
                answer = 1;
            }
            else if(strstr(response, expected_answer2) !=NULL)
            {
              answer=2;
            }
            }
           
        }
        // Waits for the asnwer with time out
    while((answer == 0) && ((millis() - previous) < timeout));   

    return answer;
}

Todo parece ir bien, pero en Xivel no recibo ningun dato.
El Feed y el API Key estan bien puestos.


Top
 Profile  
 
 Post subject: Re: Problema con subida de datos a Xively
PostPosted: Fri Jun 30, 2017 7:22 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hola Aitorto8,

Nunca hemos probado subir datos a Xively con el modulo sim908. Los ejemplos para testear el modulo son los que puedes encontrar en el tutorial, si estos te funcionan correctamente, no hay ningún problema hardware y deberás repasar tú código para hacerlo funcionar.

Un saludo.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 2 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use.