我正在尝试使用带有Arduino的xBee S6B(Wi-Fi)从我的空气质量传感器上传数据。到目前为止,我已经获得了打印传感器结果的代码,但是我需要将数据上传到Device Cloud,然后上传到Data Stream。我尝试过使用SoftwareSerial,它适用于xBee间通信(下面附带代码)。
我发现在Device Cloud的数据流中,有一个流(设备ID)/ serial / 0,它应该显示来自xBee的数据。 (来自xBee手册http://ftp1.digi.com/support/documentation/90002180_K.pdf的第62页)
以下是Arduino中的代码我用来从传感器检索数据并进行通信(到目前为止仅与其他xBee):
#include <Wire.h>
#include <SoftwareSerial.h>
#define OK 0x00
#define BUSY 0x01
#define ERROR 0x80
#define SENSOR_INTERVAL 1000
SoftwareSerial xbee(8, 9); // RX, TX
void setup() { // put your setup code here, to run once:
Serial.begin(9600);
xbee.begin(9600); // communicate using SoftwareSerial (AT Mode)
Wire.begin();
Serial.println("Running...");
}
void loop() {
Wire.requestFrom(0x5A,3); // read 3 bytes from address of IAQ-engine
// address of iAQ-engine is 0x5A
uint16_t Intensity_value;
uint8_t status;
Intensity_value = Wire.read(); // read 1st byte
Intensity_value <<= 8; // shift bits for next byte
Intensity_value |= Wire.read(); // read 2nd byte
status = Wire.read(); // read status (3rd byte)
switch (status) {
case OK:
// serial monitor
Serial.print("Air Quality (CO2) : ");
Serial.print(Intensity_value);
Serial.println(" ppm");
// xbee
xbee.print("Air Quality (CO2) : ");
xbee.print(Intensity_value);
xbee.println(" ppm");
break;
case BUSY:
Serial.println("The sensor is busy.");
// xbee
xbee.println("The sensor is busy.");
break;
case ERROR:
Serial.println("Sensor ERROR.");
xbee.println("Sensor ERROR.");
break;
default:
Serial.print("Invalid status value : ");
Serial.println(status);
xbee.print("Invalid status value : ");
xbee.println(status);
}
delay(SENSOR_INTERVAL);
}
感谢您的帮助!