arduino - Upload sensor data to xively using GPRS+GPS shield -


i´m using arduino uno , gprs+gps shield cooking hakcs (http://www.cooking-hacks.com/gprs-gps-quadband-module-for-arduino-sim908). have upload sensor data xively can´t. code have used:

int8_t answer; int onmodulepin = 2;  char aux_str[50];  char server[] = "api.xively.com"; char port[] = "8081"; string temperature = "2";  string tcp_message = "{\"method\": \"put\",\"resource\":           \"/feeds/**********/\",\"params\": {},\"headers\": {\"x-apikey\":  \"*******************************\"},\"body\": {\"version\": \"1.0.0\",\"datastreams\": [{\"id\": \"temperature\",\"current_value\": \"" + temperature + "\"}]}}";  void setup() {      pinmode(onmodulepin, output);     serial . begin(9600);      serial . println("starting...");     power_on();      delay(3000);      // sets pin code     sendatcommand("at+cpin=****", "ok", 2000);      delay(3000);      while ((sendatcommand("at+creg?", "+creg: 0,1", 500) ||     sendatcommand("at+creg?", "+creg: 0,5", 500)) == 0);      // sets apn, user name , password     sendatcommand("at+cgsockcont=1,\"ip\",\"movistar.es\"", "ok", 2000);     sendatcommand("at+csockauth=1,1,\"movistar\",\"movistar\"", "ok", 2000); }  void loop() {      char message_tcp [300];     tcp_message . tochararray(message_tcp, 300); // converting tcp_message              char inorder pass through @ command      sprintf(aux_str, "at+netopen=\"tcp\",\"8081\"");     answer = sendatcommand(aux_str, "network opened", 20000);      if (answer == 1) {         serial . println("network opened");         sprintf(aux_str, "at+tcpconnect=\"%s\",%s", server, port);         answer = sendatcommand(aux_str, "connect ok", 20000);         if (answer == 1) {             serial . println("socket opened");               string temperature = "30";             string writeapikey = "******************************************";              sprintf(aux_str, "at+tcpwrite=%d", strlen(message_tcp));              answer = sendatcommand(aux_str, ">", 20000);             if (answer == 1) {                 sendatcommand(message_tcp, "send ok", 20000);             }              sendatcommand("at+netclose", "ok", 20000);         } else {             serial . println("error opening socket");         }     } else {         serial . println("error opening network");     } }  void power_on() {      uint8_t answer = 0;      // checks if module started     answer = sendatcommand("at", "ok", 2000);     if (answer == 0) {         // power on pulse         digitalwrite(onmodulepin, high);         delay(3000);         digitalwrite(onmodulepin, low);          // waits answer module         while (answer == 0) {             // send @ every 2 seconds , wait answer             answer = sendatcommand("at", "ok", 2000);         }     } }  int8_t sendatcommand(char* atcommand, char* expected_answer1,  unsigned int timeout) {      uint8_t x = 0, answer = 0;     char response[100];     unsigned long previous;      memset(response, '\0', 100);    // initialize string      delay(100);      while (serial . available() > 0)         serial . read();    // clean input buffer      serial . println(atcommand);    // send @ command       x = 0;     previous = millis();      // loop waits answer     {          if (serial . available() != 0) {             response[x] = serial . read();             x++;             // check if desired answer in response of module             if (strstr(response, expected_answer1) != null) {                 answer = 1;             }         }         // waits asnwer time out     } while ((answer == 0) && ((millis() - previous) < timeout));      return answer; } 

i don´t know wrong or have change. it´s important me project.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -