Jump to content









Photo

Problem sending Arduino WSN datas to Carriots

Arduinosend data WSN

  • Please log in to reply
5 replies to this topic

#1 rafaelayuso

rafaelayuso

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 20 December 2015 - 10:42 AM

Hi everybody!

 

I have been developing a Wireless Sensor Networks based on Arduino for several weeks. I want send data from two nodes to Carriots but my code does not compile and i am not sure with the Carriots code but i do not know how manage that. I am a new user of this platform.

 

The WSN consists of two nodes (router) that take two soil moisture data each and send this data to the central coordinator (end device). This central coordinator sends the data to Carriot through Ethernet.

 

I managed to have datas in the Serial of the coordinator node and I succeeded in conecting with Carriots but I have this compilation error when i try send data to the Carriots platform: 

 

RECEPTOR:73: error: 'value1' was not declared in this scope
         String json = "{\"protocol\":\"v2\",\"device\":\""+DEVICE+"\",\"at\":1356390000,\"data\":{\"H_1\":\""+value1+"\"}}";
 
You can see my full code below. Notice that, currently, I am only trying to send an only one data: "value1" but I need to send "value2" data too. How can I do this? Do I need to declare a new device in Carriots for each sensor values I want to send or can I use the same device declarated? In the first case, What about the Carriot code?
 
Please, can anyone help with the compilation error and with my second question about declaration of device in Carriots and Carriot code about?
 
#include <Ethernet.h>
#include <SPI.h>
#include <XBee.h>

const String APIKEY = "________HIDDEN_________________________";
const String DEVICE = "__________HIDDEN_______________________";

XBee xbee = XBee();
ZBRxResponse zbRx = ZBRxResponse();
uint8_t text[4] = {0, 0, 0, 0};

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 177); 
IPAddress server(82,223,244,60);

EthernetClient client;

void setup () {
  delay(1000);
  Serial.begin(9600);
  xbee.begin(9600);
  Ethernet.begin(mac, ip);
  delay(1000);
}


void loop () {

  xbee.readPacket();

  if (xbee.getResponse().isAvailable()) {
    if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
      xbee.getResponse().getZBRxResponse(zbRx);

      for (int i = 0; i < 4; i++) {

        text[i] = zbRx.getData(i);
      }

      uint8_t analogHigh1 = text[0];
      uint8_t analogLow1 = text[1];
      int value1 = analogLow1 + (analogHigh1*256);
      Serial.print(value1);
      Serial.print("  ");

      uint8_t analogHigh2 = text[2];
      uint8_t analogLow2 = text[3];
      int value2 = analogLow2 + (analogHigh2*256);
      Serial.println(value2);
      sendStream();

   

      delay(500);
    }
  }

      while (client.available()) {
        char c = client.read();
        Serial.print(c);
      }
      if (!client.connected()) {
        client.stop();
      }
}

void sendStream(){

  
        if (client.connect(server, 80)) {
        Serial.println(F("connected"));
        String json = "{\"protocol\":\"v2\",\"device\":\""+DEVICE+"\",\"at\":1356390000,\"data\":{\"H_1\":\""+value1+"\"}}";

        client.println("POST /streams HTTP/1.1");
        client.println("Host: api.carriots.com");
        client.println("Accept: application/json");
        client.println("User-Agent: Arduino-Carriots");
        client.println("Content-Type: application/json");
        client.print("carriots.apikey: ");
        client.println(APIKEY);
        client.print("Content-Length: ");
        int thisLength = json.length();
        client.println(thisLength);
        client.println("Connection: close");
        client.println();
 
        client.println(json);
  }
  else {
    Serial.println(F("connection failed"));
  }
    
      }

 

Waiting for answer...

 

Thanks!



#2 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 102 posts
  • LocationMadrid, Spain.

Posted 21 December 2015 - 09:24 AM

Hi!

 

You need value1 into the sendStream function. For example:

 

...

...

uint8_t analogHigh1 = text[0]; 
uint8_t analogLow1 = text[1]; 
int value1 = analogLow1 + (analogHigh1*256); 
Serial.print(value1); 
Serial.print(" "); 
uint8_t analogHigh2 = text[2]; 
uint8_t analogLow2 = text[3]; 
int value2 = analogLow2 + (analogHigh2*256); 
Serial.println(value2); 
sendStream(value1);

...

...

void sendStream(value1){

...

...

 

I hope this help you!

 

BR



#3 rafaelayuso

rafaelayuso

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 21 December 2015 - 10:22 AM

Thank you @sdeancos but it does not work. If I try your advice I get:

 

 

RECEPTOR:26: error: variable or field 'sendStream' declared void
   Serial.begin(9600);
                       ^
/Users/rafaelayuso/Documents/Arduino/RED API/RECEPTOR/RECEPTOR.ino: In function 'void loop()':
RECEPTOR:56: error: 'sendStream' was not declared in this scope
       sendStream(value1);
                        ^
/Users/rafaelayuso/Documents/Arduino/RED API/RECEPTOR/RECEPTOR.ino: At global scope:
RECEPTOR:73: error: variable or field 'sendStream' declared void
 void sendStream(value1){
                       ^
exit status 1
variable or field 'sendStream' declared void

 

Do you have any more suggestion?

 

Waiting for answer...,

 

Regards!



#4 rafaelayuso

rafaelayuso

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 21 December 2015 - 10:29 AM

Hello again,

 

I solved it! It is enough declaring "int value1, value2 = 0" at the beginning of the code. What a stupid thing!

 

Thank for your help!



#5 rafaelayuso

rafaelayuso

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 21 December 2015 - 11:42 AM

Hello again everybody,

 

mi currently problem is that I am using my code (posted above) with the changes I suggested in the previous post. The code compiles succesfully and I can see coherent value result in the serial of the Arduino IDE (receiver and transmitter nodes) but when I open my Carriots account >> Data management >> Data Stream, I see again the same result of my first test with Carriots. I attached a screenshot.

 

Firstly, as you can see, the date is wrong, it always appears like: "25/12/2012 00:00:00" and it never changes. Why? In my code, in json, I declare:

\"at\":1356390000

because I always see this sequence in Carriot´s tutorial and code examples. How can I fix this?

 

In second place, at data stream, I always see the same data over and over: {"Humedad 1":"0"}. Why?

In my code, at json declaration I wrote: 

String json = "{\"protocol\":\"v2\",\"device\":\""+DEVICE+"\",\"at\":1356390000,\"data\":{\"H_1\":\""+value1+"\"}}";

As you can see, I wrote "H_1", not "Humedad 1"... What is wrong with this?

 

And the last point: Why am I always obtained the same value = 0? Can you help me with this?

 

 

Please, I need help. I am in the last phase of this project and I am very interested in working with Carriots but previously I need to know how this platform works!!!

 

I would be grateful for any suggestion. I think all of this could be helpful for other new users.

 

Waiting for answer,

 

BR.

 

Attached File  Captura de pantalla 2015-12-21 a la(s) 12.01.17.png   73.82K   5 downloads

 

 

 



#6 rvrostaing

rvrostaing

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 09 January 2016 - 10:54 PM

Hi,

 

Shouldn't be ''value1'' a string in stringjson sendstream() ?

 

\"at\":\"now\" should solve your second issue...

 

is it ok ?






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users