0

Using an Adafruit Feather M0 board with LoRa radio, I want to send GPS position to a receiver. When trying to create a data packet with an ISO 8601 timestamp and lat/long GPS values I am using the following code to create a char array and then send it:

char radiopacket[40] = {GPS.year + "-" + GPS.month + "-" + GPS.day + "T" + GPS.hour + ":" + GPS.minute + ":" + GPS.seconds + "Z" + "," + GPS.latitude + "," + GPS.longitude};
rf95.send((uint8_t *)radiopacket, 40);

I keep getting the error:

invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+'

Where am I going wrong?

4

2 回答 2

0

你不能在 C 中连接这样的字符串。试试类似的东西

char radiopacket[40];
sprintf(radiopacket, "%04d-%02d-%02dT%02d:%02d:%02dZ,%f,%f", GPS.year, GPS.month, GPS.day, GPS.hour, GPS.minute, GPS.seconds, GPS.latitude, GPS.longitude); 
rf95.send((uint8_t *)radiopacket, 40);

有关格式字符串 ( )的一些文档,请参见此处"%04d-..."sprintf

于 2016-08-20T15:04:48.840 回答
0

我会猜测并说你来自python。

我认为你需要的是 std::stringstream

于 2016-08-20T15:11:56.000 回答