环境
微控制器:ESP-32
传感器:LSM9DS1
IDE:Arduino1.8.9
云服务器:阿里云
协议:MQTT简介
功能:上传采集的螺旋仪信息,用于姿态检测
源码
这只是开发过程中的一次测试文件,感兴趣的可以进一步交流
#include <WiFi.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include "DFRobot_Aliyun.h"
#include "Tone32.h"
#include <Wire.h>
#include <SPI.h>
#include <SparkFunLSM9DS1.h>
#include<cJSON.h>
LSM9DS1 imu;
#define PRINT_CALCULATED
#define PRINT_SPEED 250 // 250 ms between prints
static unsigned long lastPrint = 0; // Keep track of print time
#define DECLINATION -8.58 // Declination (degrees) in Boulder, CO.
const char* WIFI_SSID = "hhh";
const char* WIFI_PASSWORD = "888333111";
String ProductKey = "a1RLLmHnGhG";
String ClientId = "1";
String DeviceName = "taJza41qu4zF0SHu8Lr6";
String DeviceSecret = "27e1e25c4a0ce409f3929166e99c3fa3";
String ALIYUN_SERVER = "iot-as-mqtt.cn-shanghai.aliyuncs.com";
uint16_t PORT = 1883;
String Identifier = "GestureDetect";
const char* subTopic = "/sys/a1RLLmHnGhG/taJza41qu4zF0SHu8Lr6/thing/event/${tsl.event.identifer}/post_reply";//****set
const char* pubTopic = "/sys/a1RLLmHnGhG/taJza41qu4zF0SHu8Lr6/thing/event/property/post";//******post
//------------------------------------------传感器参数(全局变量)
int BUTTON_PIN = 1;
int irValue=random(65,75);
int beatsPerMinute=random(68,72);
int beatAvg=random(69,71);
int Latitude=34.1436;
int Longitude=108.5837;
//-------------------------------------------
DFRobot_Aliyun myAliyun;
WiFiClient espClient;
PubSubClient client(espClient);
void connectWiFi() {
Serial.print("Connecting to ");
Serial.println(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
Serial.print("IP Adderss: ");
Serial.println(WiFi.localIP());
}
void callback(char* topic, byte* payload, unsigned int len) {
Serial.print("Recevice [");
Serial.print(topic);
Serial.print("] ");
for (