Jump to content









Photo

Error from Listener: java integer cannot be cast to string

listener error arduino dht sensor

  • Please log in to reply
5 replies to this topic

#1 bluesiivv

bluesiivv

    Newbie

  • Members
  • Pip
  • 6 posts
  • LocationSt. Thomas, USVI

Posted 17 June 2014 - 01:16 PM

Good Day. I'm a newbie when it comes to Carriots. I greatly appreciate you taking the time to read this post and assistance if you are willing and able! Thanks in advance!

 

I've created a listener in Carriots and am receiving the following alarm error:
"Listener MyTempListener@MyID.MyID: java lang Integer cannot be cast to java lang String"

My project consist on an Arduino Uno with a DHT temperature and humidity sensor. The Uno is sending temperature and humidity readings to Carriots. That part of my project works!

The listener I'm trying to create should send an e-mail when the Temperature goes above a set limit.

I see from a a few other post I may need to send the payload data in the format %%%DATA%%%. However, I be unable to get this working correctly. Below is the current working code from my Arduino project.

 

#include <SPI.h>
#include <Ethernet.h>
#include <SendCarriots.h>         // You must include the library here in order to use it in the sketch
#include "DHT.h"
#include "Wire.h"

const String APIKEY="MyAPIKey"; 		// Replace with your Carriots apikey
const String DEVICE="MyTempMonitor@MyID.MyID"; 		// Replace with the id_developer of your device
      
const int numElements=3;				// Specify the number of rows in your array, in this case 3


#define DHTPIN A3     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);


char tBuffer[15];
char hBuffer[15];
char tempFBuffer[15];

//Setup Network
// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };  
// change network settings to yours
IPAddress ip( 192, 168, 2, 127 );    
IPAddress dnslan( 192, 168, 2, 10);
IPAddress gateway( 192, 168, 2, 1 );
IPAddress subnet( 255, 255, 255, 0 );

SendCarriots sender;              // Instantiate an instance of the SendCarriots library

void setup() {
  Serial.begin(9600);             	// Start serial port
  Serial.println(F("Starting"));

  Ethernet.begin(mac,ip,dnslan,gateway,subnet);         // Start the Ethernet connection

}

void loop() {
  float h = dht.readHumidity();
    float t = dht.readTemperature();
    float tempF = (t*9)/5 + 32;
    
    Serial.print("tBuffer"); 
          Serial.println(floatToString(tBuffer, t, 2, 5));
          
          Serial.print("tempFBuffer");
          Serial.println(floatToString(tempFBuffer, tempF, 2, 5));
          
          Serial.print("hbuffer");
          Serial.println(floatToString(hBuffer, h, 2, 5));
    
    String array[numElements][2]={{"TempC", (tBuffer)}, {"TempF", (tempFBuffer)}, {"Humidity", (hBuffer)}};
          Serial.println(sender.send(array, numElements, APIKEY, DEVICE));
          
  delay(5000);                                                                								 
}
    

Finally, here is my Carriots listener config. 

IF Expression: 

context.data.TempF>74

THEN Expression: 

import com.carriots.sdk.utils.Email;
import com.carriots.sdk.utils.BasicHttp;

// Send an email to 
def email = new Email ();
email.to="myemail@mydomain.com";
email.subject="Temp Monitor";
email.message="Temp Monitor Too HOT";
email.send();

 

Thanks again for your help!

 

 



#2 sdeancos

sdeancos

    Master of Puppets

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

Posted 18 June 2014 - 05:57 AM

Hi!

 

Maybe you can try use toInteger method for java string class.

 

For example in your code:

 

context.data.TempF.toInteger() > 74

 

I hope this helps you and solve the problem!



#3 bluesiivv

bluesiivv

    Newbie

  • Members
  • Pip
  • 6 posts
  • LocationSt. Thomas, USVI

Posted 18 June 2014 - 12:52 PM

sdeancos,

 

Thanks for the reply I feel you are on the right track! I'm getting a slightly different Listener error (although quite vague). The numeric values at the end of the alarm message match the (TempF) reading I'm sending from the Arduino. However, carriots still isn't sending triggered e-mails. 
Carriots alarm error:

 

Listener MyTempListener@MyID.MyID: For input string 75 92

 

I feel as though toIntegar isn't handling the decimal properly. I first tired the If Expression you suggested:

context.data.TempF.toInteger() > 74

I then modified it slightly, adding two decimal places (my Arduino is sending TempF to Carriots with two decimal places).
 

context.data.TempF.toInteger() > 74.00

Either method produces the Listener alarms I listed above.
Thanks again for your assistance! 



#4 jpastor

jpastor

    Development leader

  • Administrators
  • 159 posts

Posted 18 June 2014 - 01:39 PM

Hello blueiivv

 

If you are sending data stream with this format: {"TempF":"24.7"}, your "if expression" would be something like this:

context.data.TempF.toBigDecimal() > 74

 

 

Hope it helps.

 

Enjoy Carriots!



#5 bluesiivv

bluesiivv

    Newbie

  • Members
  • Pip
  • 6 posts
  • LocationSt. Thomas, USVI

Posted 18 June 2014 - 01:52 PM

Thanks jpastor! 

toBigDecimal() resolved the issue. My listener is now working and sending triggered e-mails!

 

Thanks again! 



#6 sdeancos

sdeancos

    Master of Puppets

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

Posted 18 June 2014 - 04:31 PM

Ah!!! jajaja

 

I did not see that the number was a Float!

 

Excuse me!

 

Effectively the solution is to cast a decimal. Great jpastor!

 

Enjoy Carriots!







Also tagged with one or more of these keywords: listener, error, arduino, dht sensor

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users