我正在为一个大学项目开发Arduino板(微处理器: ATMega328P)。我想建立一个GPS跟踪器,接收数据,存储它,并通过SIGFOX模块转发它。基本上,我能够接收数据,并且能够通过串行发送简单的SIGFOX命令。
#include <TinyGPS++.h>
#include <String.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 4800;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
Serial.begin(115200);
ss.begin(GPSBaud);
Serial.println(F("DeviceExample.ino"));
Serial.println(TinyGPSPlus::libraryVersion());
Serial.println();
}
void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read())) {
Serial.print(gps.location.lat(), 6); // 4 bytes
Serial.print(F(",")); // 1 byte
Serial.print(gps.location.lng(), 6); // 4 bytes
Serial.print('\n');
delay(4000);
}
if (millis() > 5000 && gps.charsProcessed() < 10){
Serial.println(F("No GPS detected: check wiring."));
while (true);
}
}这会在屏幕上正确地打印出我需要存储的两个值(纬度和经度)。这是TinyGPS++.cpp中的代码部分:
double TinyGPSLocation::lat()
{
updated = false;
double ret = rawLatData.deg + rawLatData.billionths / 1000000000.0;
return rawLatData.negative ? -ret : ret;
}
double TinyGPSLocation::lng()
{
updated = false;
double ret = rawLngData.deg + rawLngData.billionths / 1000000000.0;
return rawLngData.negative ? -ret : ret;
}现在我想存储这个数据并通过SIGFOX模块发送它。SIGFOX命令为:
“N X”
其中N表示要传输的字节数,X是这些字节的值。例如:'1 255‘是值为255的1字节,并返回FF作为输出。
问题是这些值是双精度的,所以我不知道如何在SIGFOX命令中编写它们。另一个问题是,我不知道如何在代码中创建两个串行通信。我试过了,但好像不起作用。
非常感谢你提前这么做。
发布于 2018-12-23 04:46:59
我在SIGFOX上看到了一些API信息,我猜是这样的。即使不是这样,它也可能足够接近我想要表达的观点。
https://support.sigfox.com/apidocs#operation/getDevice
你需要在某种程度上理解什么是IEEE754,根据我的经验,这就是设备如何来回传递数据,如果你查看原始比特流的话。
https://en.wikipedia.org/wiki/IEEE_754
因此,在大多数平台上,它是一个双精度型,超过8个字节,而对于一个浮点型,发送4个字节。当您在调试模式下将鼠标悬停在变量上时,IDE/编译器会为您处理此问题,并为您提供带有小数点的数字。
为了制作另一个串口,你需要设置另一个变量,并传入该设备的波特率等。
https://stackoverflow.com/questions/53898896
复制相似问题