# Adafruit IO time type conversion

**URL:** <https://forum.arduino.cc/t/adafruit-io-time-type-conversion/1166309>\
**Category:** Programming\
**Created:** [September 7, 2023, 11:39pm UTC](https://forum.arduino.cc/t/adafruit-io-time-type-conversion/1166309 "2023-09-07T23:39:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidanb](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aidanb](https://forum.arduino.cc/u/aidanb)\
**Post date:** [September 7, 2023, 11:39pm UTC](https://forum.arduino.cc/t/adafruit-io-time-type-conversion/1166309/1 "2023-09-07T23:39:04Z")

</div>

Hello,

In other AIO sketches, the data-\>toLong() function would work just fine. However, in the time example, I unfortunately don't know how this type is different and why something like this won't work:

void handleSecs(char \*data, uint16\_t len) {  
Serial.print("Seconds Feed: ");  
Serial.println(data);  
slt = data-\>toLong();  
}

Getting this error: request for member 'toChar' in '\* data', which is of non-class type 'char'

Looking to convert the time "data" to a long for use elsewhere in the program.

Any help would be greatly appreciated.

Aidan

This is the basic code I'm working with.

\\

// Adafruit IO Time Topic Subscription Example  
//  
// Adafruit invests time and resources providing this open source code.  
// Please support Adafruit and open source hardware by purchasing  
// products from Adafruit!  
//  
// Written by Adam Bachman, Brent Rubell for Adafruit Industries  
// Copyright (c) 2018 Adafruit Industries  
// Licensed under the MIT license.  
//  
// All text above must be included in any redistribution.

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Configuration \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

// edit the config.h tab and enter your Adafruit IO credentials  
// and any additional configuration needed for WiFi, cellular,  
// or ethernet clients.  
#include "config.h"

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Example Starts Here \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

// set up the 'time/seconds' topic  
AdafruitIO\_Time \*seconds = io.time(AIO\_TIME\_SECONDS);

// set up the 'time/milliseconds' topic  
AdafruitIO\_Time \*msecs = io.time(AIO\_TIME\_MILLIS);

// set up the 'time/ISO-8601' topic  
AdafruitIO\_Time \*iso = io.time(AIO\_TIME\_ISO);

void setup() {

// start the serial connection  
Serial.begin(115200);

// wait for serial monitor to open  
while(! Serial);

Serial.print("Connecting to Adafruit IO");

// start MQTT connection to [io.adafruit.com](http://io.adafruit.com)  
io.connect();

// attach message handler for the seconds feed  
seconds-\>onMessage(handleSecs);

// attach a message handler for the msecs feed  
msecs-\>onMessage(handleMillis);

// attach a message handler for the ISO feed  
iso-\>onMessage(handleISO);

// wait for an MQTT connection  
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus  
// method to check on MQTT connection status specifically  
while(io.mqttStatus() \< AIO\_CONNECTED) {  
Serial.print(".");  
delay(500);  
}

// we are connected  
Serial.println();  
Serial.println(io.statusText());

}

void loop() {

// io.run(); is required for all sketches.  
// it should always be present at the top of your loop  
// function. it keeps the client connected to  
// [io.adafruit.com](http://io.adafruit.com), and processes any incoming data.  
io.run();

// Because this sketch isn't publishing, we don't need  
// a delay() in the main program loop.

}

// message handler for the seconds feed  
void handleSecs(char \*data, uint16\_t len) {  
Serial.print("Seconds Feed: ");  
Serial.println(data);  
}

// message handler for the milliseconds feed  
void handleMillis(char \*data, uint16\_t len) {  
Serial.print("Millis Feed: ");  
Serial.println(data);  
}

// message handler for the ISO-8601 feed  
void handleISO(char \*data, uint16\_t len) {  
Serial.print("ISO Feed: ");  
Serial.println(data);  
}

```arduino

```

---

<div class="post-metadata">

**Author:** ![kolaha](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kolaha/32/966427_2.png) [@kolaha](https://forum.arduino.cc/u/kolaha)\
**Post date:** [September 7, 2023, 11:46pm UTC](https://forum.arduino.cc/t/adafruit-io-time-type-conversion/1166309/2 "2023-09-07T23:46:44Z")

</div>

use code tags

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [September 8, 2023, 2:55am UTC](https://forum.arduino.cc/t/adafruit-io-time-type-conversion/1166309/4 "2023-09-08T02:55:43Z")

</div>

Your code is hard to read, if you read the forum guidelines you would know about code tags and posted accordingly.

---

<div class="post-metadata">

**Author:** ![aidanb](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@aidanb](https://forum.arduino.cc/u/aidanb)\
**Post date:** [September 9, 2023, 5:31pm UTC](https://forum.arduino.cc/t/adafruit-io-time-type-conversion/1166309/5 "2023-09-09T17:31:09Z")

</div>

```arduino
void handleSecs(char *data, uint16_t len) {
Serial.print("Seconds Feed: ");
Serial.println(data);
slt = data->toLong();
}

```

Getting this error: request for member 'toChar' in '\* data', which is of non-class type 'char'

Looking to convert the time "data" to a long for use elsewhere in the program.

Any help would be greatly appreciated.

Aidan

This is the basic AIO time example I am working off of.

```arduino

// Adafruit IO Time Topic Subscription Example
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Adam Bachman, Brent Rubell for Adafruit Industries
// Copyright (c) 2018 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/ **************************Configuration*********************************** /

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/ ************************Example Starts Here******************************* /

// set up the 'time/seconds' topic
AdafruitIO_Time *seconds = io.time(AIO_TIME_SECONDS);

// set up the 'time/milliseconds' topic
AdafruitIO_Time *msecs = io.time(AIO_TIME_MILLIS);

// set up the 'time/ISO-8601' topic
AdafruitIO_Time *iso = io.time(AIO_TIME_ISO);

void setup() {

// start the serial connection
Serial.begin(115200);

// wait for serial monitor to open
while(! Serial);

Serial.print("Connecting to Adafruit IO");

// start MQTT connection to [io.adafruit.com](http://io.adafruit.com)
io.connect();

// attach message handler for the seconds feed
seconds->onMessage(handleSecs);

// attach a message handler for the msecs feed
msecs->onMessage(handleMillis);

// attach a message handler for the ISO feed
iso->onMessage(handleISO);

// wait for an MQTT connection
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
// method to check on MQTT connection status specifically
while(io.mqttStatus() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}

// we are connected
Serial.println();
Serial.println(io.statusText());

}

void loop() {

// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// [io.adafruit.com](http://io.adafruit.com), and processes any incoming data.
io.run();

// Because this sketch isn't publishing, we don't need
// a delay() in the main program loop.

}

// message handler for the seconds feed
void handleSecs(char *data, uint16_t len) {
Serial.print("Seconds Feed: ");
Serial.println(data);
}

// message handler for the milliseconds feed
void handleMillis(char *data, uint16_t len) {
Serial.print("Millis Feed: ");
Serial.println(data);
}

// message handler for the ISO-8601 feed
void handleISO(char *data, uint16_t len) {
Serial.print("ISO Feed: ");
Serial.println(data);
}

```

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [September 9, 2023, 6:40pm UTC](https://forum.arduino.cc/t/adafruit-io-time-type-conversion/1166309/7 "2023-09-09T18:40:30Z")

</div>

If slt is suitably declared, try  
`slt = atol(data);`

This will work if "data" is a zero-terminated character array (a C-string).

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 7, 2024, 6:41pm UTC](https://forum.arduino.cc/t/adafruit-io-time-type-conversion/1166309/8 "2024-03-07T18:41:08Z")

</div>

Closed on March 7, 2024, 6:41pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
