首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arduino SigFox温度数据问题

Arduino SigFox温度数据问题
EN

Stack Overflow用户
提问于 2018-09-20 10:53:53
回答 1查看 466关注 0票数 0

有人能帮我处理这个西格福克斯的设置吗?我做错了什么?

我唯一想要实现的就是将内部温度和状态发布到sigfox后端。每15分钟公布一次数据。配置了一封来自服务部门的电子邮件,显示以摄氏度为单位的温度。

张贴到后端是有效的。然而,电子邮件消息和数据似乎不一致。在调试模式下运行代码时。以摄氏度表示温度是正确的。

有手册吗?

代码Arduino MKR FOX 1200

Temp.ino

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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后端-电子邮件回调

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-22 07:51:26

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52423487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档