Arduino SigFox 温度数据问题

Arduino SigFox temperature data Problems

有人可以帮我设置 Sigfox 吗? 我做错了什么? :-)

我唯一想要实现的是 post 内部温度和 sigfox 后端的状态。 每 15 分钟,数据将被 posted。 A 配置了来自服务的电子邮件,显示以摄氏度为单位的温度。

正在向后端发帖。 然而,电子邮件信息和数据似乎并不对应。 当 运行 代码处于调试模式时。温度正确显示为摄氏度。

有手册吗?

代码 Arduino MKR FOX 1200

Temp.ino

#include <ArduinoLowPower.h>
#include <SigFox.h>
#include "conversions.h"

// Set oneshot to false to trigger continuous mode when you finisched setting up the whole flow
int oneshot = false;


#define STATUS_OK     0

/*
    ATTENTION - the structure we are going to send MUST
    be declared "packed" otherwise we'll get padding mismatch
    on the sent data - see http://www.catb.org/esr/structure-packing/#_structure_alignment_and_padding
    for more details
*/
typedef struct __attribute__ ((packed)) sigfox_message {
  int16_t moduleTemperature;
  uint8_t lastMessageStatus;
} SigfoxMessage;

// stub for message which will be sent
SigfoxMessage msg;

void setup() {

  if (oneshot == true) {
    // Wait for the serial
    Serial.begin(115200);
    while (!Serial) {}
  }

  if (!SigFox.begin()) {
    // Something is really wrong, try rebooting
    // Reboot is useful if we are powering the board using an unreliable power source
    // (eg. solar panels or other energy harvesting methods)
    reboot();
  }

  //Send module to standby until we need to send a message
  SigFox.end();

  if (oneshot == true) {
    // Enable debug prints and LED indication if we are testing
    SigFox.debug();
  }

 }

void loop() {
  // Every 15 minutes, read all the sensor and send the data
  // Let's try to optimize the data format
  // Only use floats as intermediate representaion, don't send them directly

  //sensors_event_t event;

  // Start the module
  SigFox.begin();
  // Wait at least 30ms after first configuration (100ms before)
  delay(100);

  // We can only read the module temperature before SigFox.end()
  float temperature = SigFox.internalTemperature();
  msg.moduleTemperature = convertoFloatToInt16(temperature, 60, -60);

  if (oneshot == true) {
    Serial.println("Internal temp: " + String(temperature));
  }

  // Clears all pending interrupts
  SigFox.status();
  delay(1);

  SigFox.beginPacket();
  SigFox.write((uint8_t*)&msg, 12);

  msg.lastMessageStatus = SigFox.endPacket();

  if (oneshot == true) {
    Serial.println("Status: " + String(msg.lastMessageStatus));
  }

  SigFox.end();

  if (oneshot == true) {
    // spin forever, so we can test that the backend is behaving correctly
    while (1) {}
  }

  //Sleep for 15 minutes
  LowPower.sleep(1 * 60 * 1000);
}

void reboot() {
  NVIC_SystemReset();
  while (1);
}

Conversion.h

#define UINT16_t_MAX  65536
#define INT16_t_MAX   UINT16_t_MAX/2

int16_t convertoFloatToInt16(float value, long max, long min) {
  float conversionFactor = (float) (INT16_t_MAX) / (float)(max - min);
  return (int16_t)(value * conversionFactor);
}

uint16_t convertoFloatToUInt16(float value, long max, long min = 0) {
  float conversionFactor = (float) (UINT16_t_MAX) / (float)(max - min);
  return (uint16_t)(value * conversionFactor);
}

设置 Sigfox 后端 - 电子邮件回调

使用当前的 convertoFloatToInt16,将无法直接从 Sigfox 后端在电子邮件中显示真实温度。

您要么需要使用从 Sigfox 后端到实现 convertoFloatToUInt16 的服务器的回调,然后发送电子邮件,要么以 Sigfox 后端可以本地解码的格式发送温度(32 位浮点数可能是最合适)。