SMS TEXTING CAT DISH ERROR COMPILE

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
legacy_eternal
 
Posts: 11
Joined: Tue Dec 10, 2013 6:22 am

SMS TEXTING CAT DISH ERROR COMPILE

Post by legacy_eternal »

Getting this error message in the code provided in your tutorial:

I have made no changes, so for simplicity I am posting the errors I received. I just want to see if the code would compile as it is before I started making changes and it does not.

SMS_Pet_Food_Dish.ino: In function 'void snsPublish(const char*, const char*, long unsigned int)':
SMS_Pet_Food_Dish:192: error: 'DateTime' was not declared in this scope
SMS_Pet_Food_Dish:192: error: expected `;' before 'dt'
SMS_Pet_Food_Dish:195: error: 'dt' was not declared in this scope

Also if I wanted to see the amount of times lets say a dog goes to the bowl to eat, to monitor someone over-feeding what is the set up change for the IR detector, I have looked at the example it has not quite clicked. I have also used a basic FSR for a prototype purposes to detects the change in pressure, of food in the bowl, can that be sent as a alert as well? Thanks and regards...

Code: Select all

// Publish a message to an SNS topic.
// Note, both the topic and message strings _MUST_ be URL encoded before calling this function!
void snsPublish(const char* topic, const char* message, unsigned long currentTime) {
  // Set dateTime to the URL encoded ISO8601 format string.
  DateTime dt(currentTime);
  char dateTime[25];
  memset(dateTime, 0, 25);
  dateTime8601UrlEncoded(dt.year(), dt.month(), dt.day(), dt.hour(), dt.minute(), dt.second(), dateTime);

  // Generate the signature for the request.
  // For details on the AWS signature process, see: 
  //   http://docs.aws.amazon.com/general/latest/gr/signature-version-2.html
  Sha1.initHmac((uint8_t*)AWS_SECRET_ACCESS_KEY, strlen(AWS_SECRET_ACCESS_KEY));
  Sha1.print(F("POST\n"));
  Sha1.print(AWS_HOST); Sha1.print(F("\n"));
  Sha1.print(F("/\n"));
  Sha1.print(F("AWSAccessKeyId="));
  Sha1.print(AWS_ACCESS_KEY);
  Sha1.print(F("&Action=Publish"));
  Sha1.print(F("&Message="));
  Sha1.print(message);
  Sha1.print(F("&SignatureMethod=HmacSHA1"));
  Sha1.print(F("&SignatureVersion=2"));
  Sha1.print(F("&Timestamp="));
  Sha1.print(dateTime);
  Sha1.print(F("&TopicArn="));
  Sha1.print(topic);
  Sha1.print(F("&Version=2010-03-31"));
  
  // Convert signature to base64
  // Adapted from Adafruit code for SendTweet example.
  uint8_t *in, out, i, j;
  char b64[27];
  memset(b64, 0, sizeof(b64));
  static const char PROGMEM b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  for(in = Sha1.resultHmac(), out=0; ; in += 3) { // octets to sextets
    b64[out++] =   in[0] >> 2;
    b64[out++] = ((in[0] & 0x03) << 4) | (in[1] >> 4);
    if(out >= 26) break;
    b64[out++] = ((in[1] & 0x0f) << 2) | (in[2] >> 6);
    b64[out++] =   in[2] & 0x3f;
  }
  b64[out] = (in[1] & 0x0f) << 2;
  // Remap sextets to base64 ASCII chars
  for(i=0; i<=out; i++) b64[i] = pgm_read_byte(&b64chars[(unsigned char)b64[i]]);
  
  // URL encode base64 signature.  Note, this is not a general URL encoding routine!
  char b64Encoded[100];
  memset(b64Encoded, 0, sizeof(b64Encoded));
  for(i=0, j=0; i<=out; i++) {
    uint8_t ch = b64[i];
    if (ch == '+') {
      b64Encoded[j++] = '%';  
      b64Encoded[j++] = '2';  
      b64Encoded[j++] = 'B';  
    }
    else if (ch == '/') {
      b64Encoded[j++] = '%';  
      b64Encoded[j++] = '2';  
      b64Encoded[j++] = 'F'; 
    }
    else {
      b64Encoded[j++] = ch;
    }
  }
  b64Encoded[j++] = '%';
  b64Encoded[j++] = '3';
  b64Encoded[j++] = 'D';
  
  // Make request to SNS API.
  uint32_t ip = 0;
  while (ip == 0) {
    if (!cc3000.getHostByName(AWS_HOST, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }
  Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
  if (http://www.connected()) {    
    http://www.fastrprint(F("POST /?"));
    http://www.fastrprint(F("AWSAccessKeyId="));
    http://www.fastrprint(AWS_ACCESS_KEY);
    http://www.fastrprint(F("&Action=Publish"));
    http://www.fastrprint(F("&Message="));
    http://www.fastrprint(message);
    http://www.fastrprint(F("&SignatureMethod=HmacSHA1"));
    http://www.fastrprint(F("&SignatureVersion=2"));
    http://www.fastrprint(F("&Timestamp="));
    http://www.fastrprint(dateTime);
    http://www.fastrprint(F("&TopicArn="));
    http://www.fastrprint(topic);
    http://www.fastrprint(F("&Version=2010-03-31"));
    http://www.fastrprint(F("&Signature="));
    http://www.fastrprint(b64Encoded);  
    http://www.fastrprint(F(" HTTP/1.1\r\nHost: "));
    http://www.fastrprint(AWS_HOST);
    http://www.fastrprint(F("\r\nContent-Length: 0\r\n\r\n"));
  } 
  else {
    Serial.println(F("Connection failed"));    
    http://www.close();
    return;
  }
  
  // Read data until either the connection is closed, or the idle timeout is reached.
  Serial.println(F("AWS response:"));
  unsigned long lastRead = millis();
  while (http://www.connected() && (millis() - lastRead < TIMEOUT_MS)) {
    while (http://www.available()) {
      char c = http://www.read();
      Serial.print(c);
      lastRead = millis();
    }
  }
  http://www.close();
}

// Fill a 24 character buffer with the date in URL-encoded ISO8601 format, like '2013-01-01T01%3A01%3A01Z'.  
// Buffer MUST be at least 24 characters long!
void dateTime8601UrlEncoded(int year, byte month, byte day, byte hour, byte minute, byte seconds, char* buffer) {
  ultoa(year, buffer, 10);
  buffer[4] = '-';
  btoa2Padded(month, buffer+5, 10);
  buffer[7] = '-';
  btoa2Padded(day, buffer+8, 10);
  buffer[10] = 'T';
  btoa2Padded(hour, buffer+11, 10);
  buffer[13] = '%';
  buffer[14] = '3';
  buffer[15] = 'A';
  btoa2Padded(minute, buffer+16, 10);
  buffer[18] = '%';
  buffer[19] = '3';
  buffer[20] = 'A';
  btoa2Padded(seconds, buffer+21, 10);
  buffer[23] = 'Z';
}

// Print a value from 0-99 to a 2 character 0 padded character buffer.
// Buffer MUST be at least 2 characters long!
void btoa2Padded(uint8_t value, char* buffer, int base) {
  if (value < base) {
    *buffer = '0';
    ultoa(value, buffer+1, base);
  }
  else {
    ultoa(value, buffer, base); 
  }
}

// getTime function adapted from CC3000 ntpTest sketch.
// Minimalist time server query; adapted from Adafruit Gutenbird sketch,
// which in turn has roots in Arduino UdpNTPClient tutorial.
unsigned long getTime(void) {
  Adafruit_CC3000_Client client;
  uint8_t       buf[48];
  unsigned long ip, startTime, t = 0L;

  // Hostname to IP lookup; use NTP pool (rotates through servers)
  if(cc3000.getHostByName("pool.ntp.org", &ip)) {
    static const char PROGMEM
      timeReqA[] = { 227,  0,  6, 236 },
      timeReqB[] = {  49, 78, 49,  52 };

    startTime = millis();
    do {
      client = cc3000.connectUDP(ip, 123);
    } while((!client.connected()) &&
            ((millis() - startTime) < TIMEOUT_MS));

    if(client.connected()) {
      // Assemble and issue request packet
      memset(buf, 0, sizeof(buf));
      memcpy_P( buf    , timeReqA, sizeof(timeReqA));
      memcpy_P(&buf[12], timeReqB, sizeof(timeReqB));
      client.write(buf, sizeof(buf));

      memset(buf, 0, sizeof(buf));
      startTime = millis();
      while((!client.available()) &&
            ((millis() - startTime) < TIMEOUT_MS));
      if(client.available()) {
        client.read(buf, sizeof(buf));
        t = (((unsigned long)buf[40] << 24) |
             ((unsigned long)buf[41] << 16) |
             ((unsigned long)buf[42] <<  8) |
              (unsigned long)buf[43]) - 2208988800UL;
      }
      client.close();
    }
  }
  return t;
}
Last edited by adafruit_support_bill on Thu Feb 13, 2014 8:31 am, edited 1 time in total.
Reason: Fixed code tags

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: SMS TEXTING CAT DISH ERROR COMPILE

Post by adafruit_support_rick »

You seem to be missing the RTCLib. Download it from here and install it in your libraries folder:
https://github.com/adafruit/RTClib

Edit: I've added a note to the tutorial that the RTCLib is required

legacy_eternal
 
Posts: 11
Joined: Tue Dec 10, 2013 6:22 am

Re: SMS TEXTING CAT DISH ERROR COMPILE

Post by legacy_eternal »

Thank you for your prompt response.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”