Huyi преди 1 година
родител
ревизия
4bd7e73470
променени са 6 файла, в които са добавени 123 реда и са изтрити 103 реда
  1. 15 1
      Drivers/CONFIG.h
  2. 87 33
      Drivers/Modules/Tuoreniot.c
  3. 1 25
      Drivers/Modules/bc260y/Bc260y_Regist.c
  4. 4 30
      Drivers/Modules/ec800m/Ec800m_Regist.c
  5. 12 1
      Hardware/GPIOA.c
  6. 4 13
      User/main.c

+ 15 - 1
Drivers/CONFIG.h

@@ -13,8 +13,22 @@
 
 
 //#define EC800M 1 //4G开关,不能数字开头
-#define BC260Y 1  // NB
+//#define BC260Y 1  // NB
+#define ESP32 1		//WiFi
 
+#if ESP32			
+// 胡一的配置
+
+//睡眠相关IO配置 
+#define WAKE_GPIO_RCC RCC_APB2Periph_GPIOA
+#define WAKE_GPIO GPIOA
+#define DEEP_SLEEP_GPIO_Pin  GPIO_Pin_6 	// 深睡眠的引脚
+#define LIGHT_SLEEP_GPIO_Pin GPIO_Pin_7 	// 浅睡眠的引脚
+//flash相关配置
+#define FLASH_SIZE 	64
+#define FLASH_SAVE_ADDR 0X0800F800
+
+#endif
 
 
 

+ 87 - 33
Drivers/Modules/Tuoreniot.c

@@ -15,6 +15,9 @@
 #include "Timer_Module.h"
 #include "CoAP_Util.h"
 
+// 泵号
+extern uint8_t mcu_id[8];
+
 // 注册时用的密钥
 char regist_key[17]="tuorenzhinenghua";
 
@@ -29,13 +32,14 @@ uint16_t REGIST_PORT = 8888; //
 #endif
 
 #if TEST_ENV
+
 // 开发环境
-//char * REGIST_SERVER = "b21759p174.iok.la" ; //注册服务器地址
-//uint16_t REGIST_PORT = 43097; //端口号
+//char * REGIST_SERVER = "192.168.103.172" ; //注册服务器地址
+//uint16_t REGIST_PORT = 8888; //端口号
 
+char * REGIST_SERVER = "18017zi0ec26.vicp.fun" ; //注册服务器地址
+uint16_t REGIST_PORT = 58562; //端口号
 
-char * REGIST_SERVER = "frp-fun.top" ; //注册服务器地址
-uint16_t REGIST_PORT = 27827; //端口号
 
 #endif
 
@@ -46,10 +50,6 @@ static void ReadRegistResponseFromFlash(void);
 // 将注册响应写入到flash中
 static void WriteRegistResponseToFlash(void);
 
-
-
-
-
 // 注册结果
 struct TUORENIOT_RegistResponseStruct regist_response = {
 	.version = 1
@@ -66,15 +66,33 @@ static void InitClientId(void)
 	strcat(ClientID, regist_response.deviceId);
 }
 
-/**
-* 
-*注册数据解密
-*/
+/*************************************** 注册信息打包函数 ***************************************/
+void TUORENIOT_PackRegistRequest(uint8_t * pack_data, uint16_t * pack_data_length, struct TUORENIOT_RegistRequestStruct * registParams)
+{
+	
+	Log_Printf_Debug("mcu_id: %s\r\n", mcu_id);
+	byteToHexStr(mcu_id, registParams->deviceId, sizeof(mcu_id));
+
+	sprintf((char *)(pack_data + 2), "{\"version\":\"%d\",\"networkType\":\"%d\",\"networkProtocol\":\"%d\",\"productId\":\"%s\",\"deviceId\":\"%s\",\"userId\":\"%s\"}", 
+	registParams->version, registParams->networkType, registParams->networkProtocol, registParams->productId, registParams->deviceId, registParams->userId); // 拼接AT指令
+	Log_Printf_Debug("%s\r\n", (char *)(pack_data + 2));
+	
+	uint16_t datalen = utils_aes128_ECB_base64_enc_with_length(regist_key, (pack_data + 2));
+	
+	pack_data[0] = datalen>>8;//头2个字节赋值数据长度
+	pack_data[1] = datalen;
+
+	* pack_data_length = datalen + 2;
+}
+
+/*************************************** 注册数据解密函数 ***************************************/
+
+static int wifi_count=0;	//WiFi信息计数变量
 uint8_t TUORENIOT_AnalysisRegistData(uint8_t * regist_data, uint16_t regist_data_length)
 {
-//	Log_Printf_Debug("regist_data: \r\n");
-//	Log_SendHex(regist_data, regist_data_length);
-//	Log_Printf_Debug("\r\n");
+	Log_Printf_Debug("regist_data: \r\n");
+	Log_SendHex(regist_data, regist_data_length);
+	Log_Printf_Debug("\r\n");
 
 	uint8_t result;
 	utils_aes128_ECB_base64_dec(regist_key,regist_data,regist_data_length);
@@ -90,19 +108,56 @@ uint8_t TUORENIOT_AnalysisRegistData(uint8_t * regist_data, uint16_t regist_data
 	{
 		regist_response.code = cJSON_GetObjectItem(json, "code")->valueint;
 		regist_response.version = cJSON_GetObjectItem(json, "version")->valueint;
-		regist_response.userId = cJSON_GetObjectItem(json, "userId")->valueint;
-		strcpy(regist_response.networkProtocol, cJSON_GetObjectItem(json, "networkProtocol")->valuestring);
-		strcpy(regist_response.platform, cJSON_GetObjectItem(json, "platform")->valuestring);
-		strcpy(regist_response.deviceSecret, cJSON_GetObjectItem(json, "deviceSecret")->valuestring);
+		regist_response.platform = cJSON_GetObjectItem(json, "platform")->valueint;
+		regist_response.networkType = cJSON_GetObjectItem(json, "networkType")->valueint;
+		regist_response.networkProtocol = cJSON_GetObjectItem(json, "networkProtocol")->valueint;
 		strcpy(regist_response.productId, cJSON_GetObjectItem(json, "productId")->valuestring);
 		strcpy(regist_response.deviceId, cJSON_GetObjectItem(json, "deviceId")->valuestring);
+		strcpy(regist_response.userId, cJSON_GetObjectItem(json, "userId")->valuestring);
+		strcpy(regist_response.deviceSecret, cJSON_GetObjectItem(json, "deviceSecret")->valuestring);
 		strcpy(regist_response.remoteAddress, cJSON_GetObjectItem(json, "remoteAddress")->valuestring);
 		regist_response.remotePort = cJSON_GetObjectItem(json, "remotePort")->valueint;
 		
-		regist_response.wifiNumber = 3;
-		// 解析wifi
-		
-		
+		// 判断是否解析WiFi信息
+		if(regist_response.networkType == 3)
+		{
+			Log_Printf_Debug("---------------------解析WiFi信息----------------------\r\n");
+			cJSON *wifi_Array = cJSON_GetObjectItem(json, "wifi");
+			regist_response.wifiNumber = cJSON_GetArraySize(wifi_Array);
+			Log_Printf_Debug("wifiNumber=%d\r\n",regist_response.wifiNumber);
+			if (cJSON_IsArray(wifi_Array)) 
+			{  	
+				cJSON *wifiElement = NULL;  
+				cJSON_ArrayForEach(wifiElement, wifi_Array) 
+				{  
+					// 提取wifiName  
+					cJSON *wifiName = cJSON_GetObjectItem(wifiElement, "wifiName");
+					strcpy(regist_response.wifi[wifi_count].wifiName,wifiName->valuestring);	
+					// 提取wifiPassword  
+					cJSON *wifiPassword = cJSON_GetObjectItem(wifiElement, "wifiPassword"); 
+					strcpy(regist_response.wifi[wifi_count].wifiPassword,wifiPassword->valuestring);
+					//解析WiFi信息计数
+					wifi_count++;
+				}	
+			}
+			//校验解析的WiFi信息数目是否正确
+			if(wifi_count != regist_response.wifiNumber)
+			{
+				Log_Printf_Debug("wifi_count=%d\r\n",wifi_count);
+				Log_Printf_Debug("解析wifi信息ERROR!!!\r\n");
+				result = 0;
+				cJSON_Delete(json);
+				return result;
+			}
+			//打印解析的WiFi信息
+			Log_Printf_Debug("解析出%d组wifi信息如下:\r\n",wifi_count);
+			for(int i=0;i<wifi_count;i++)
+			{
+				Log_Printf_Debug("wifi[%d]->wifiName: %s\r\n", i,regist_response.wifi[i].wifiName);
+				Log_Printf_Debug("wifi[%d]->wifiPassword: %s\r\n", i,regist_response.wifi[i].wifiPassword);
+			}
+			Log_Printf_Debug("-------------------------结束--------------------------\r\n");
+		}
 		result = 1;
 		WriteRegistResponseToFlash();
 	}
@@ -357,34 +412,33 @@ void TUORENIOT_PrintfRegistRequestStruct(struct TUORENIOT_RegistRequestStruct *
 {
 	Log_Printf("------print regist params start------\r\n");
 	Log_Printf("version=%d\r\n", regist_params_struct->version);
-	Log_Printf("networkType=%s\r\n", regist_params_struct->networkType);
-	Log_Printf("networkProtocol=%s\r\n", regist_params_struct->networkProtocol);
+	Log_Printf("networkType=%d\r\n", regist_params_struct->networkType);
+	Log_Printf("networkProtocol=%d\r\n", regist_params_struct->networkProtocol);
+	Log_Printf("productId=%s\r\n", regist_params_struct->productId);
 	Log_Printf("deviceId=%s\r\n", regist_params_struct->deviceId);
-	Log_Printf("platform=%s\r\n", regist_params_struct->platform);
-	Log_Printf("userId=%d\r\n", regist_params_struct->userId);
+	Log_Printf("userId=%s\r\n", regist_params_struct->userId);
 	Log_Printf("------print regist params end------\r\n");
 }
 
-
 void TUORENIOT_PrintfRegistResponseStruct(void)
 {
 	Log_Printf("------print regist result start------\r\n");
 	Log_Printf("code=%d\r\n", regist_response.code);
 	Log_Printf("version=%d\r\n", regist_response.version);
-	Log_Printf("networkProtocol=%s\r\n", regist_response.networkProtocol);
-	Log_Printf("platform=%s\r\n", regist_response.platform);
+	Log_Printf("platform=%d\r\n", regist_response.platform);
+	Log_Printf("networkType=%d\r\n", regist_response.networkType);
+	Log_Printf("networkProtocol=%d\r\n", regist_response.networkProtocol);
+	Log_Printf("productId=%s\r\n", regist_response.productId);
 	Log_Printf("deviceId=%s\r\n", regist_response.deviceId);
+	Log_Printf("userId=%s\r\n", regist_response.userId);
 	Log_Printf("deviceSecret=%s\r\n", regist_response.deviceSecret);
 	Log_Printf("remoteAddress=%s\r\n", regist_response.remoteAddress);
 	Log_Printf("remotePort=%d\r\n", regist_response.remotePort);
-	Log_Printf("productId=%s\r\n", regist_response.productId);
-	Log_Printf("userId=%d\r\n", regist_response.userId);
 	Log_Printf("wifiNumber=%d\r\n", regist_response.wifiNumber);
 	Log_Printf("------print regist result end------\r\n");
 }
 
 
-
 // 初始化
 void TUORENIOT_Init(void)
 {

+ 1 - 25
Drivers/Modules/bc260y/Bc260y_Regist.c

@@ -17,8 +17,7 @@
 
 #include "bc260y.h"
 
-// 泵号
-extern uint8_t mcu_id[8];
+
 // socket ID
 static uint8_t connectID = 2;
 
@@ -35,29 +34,6 @@ static struct TUORENIOT_RegistRequestStruct regist_request = {
 static char pridnsaddr[20];
 
 
-/**
-* 
-*注册参数信息打包
-*/
-void TUORENIOT_PackRegistRequest(uint8_t * pack_data, uint16_t * pack_data_length, struct TUORENIOT_RegistRequestStruct * registParams)
-{
-	
-	Log_Printf_Debug("mcu_id: %s\r\n", mcu_id);
-	byteToHexStr(mcu_id, registParams->deviceId, sizeof(mcu_id));
-
-	sprintf((char *)(pack_data + 2), "{\"version\":\"%d\",\"networkType\":\"%d\",\"networkProtocol\":\"%d\",\"productId\":\"%s\",\"deviceId\":\"%s\",\"userId\":\"%s\"}", 
-	registParams->version, registParams->networkType, registParams->networkProtocol, registParams->productId, registParams->deviceId, registParams->userId); // 拼接AT指令
-	Log_Printf_Debug("%s\r\n", (char *)(pack_data + 2));
-	
-	uint16_t datalen = utils_aes128_ECB_base64_enc_with_length(regist_key, (pack_data + 2));
-	
-	pack_data[0] = datalen>>8;//头2个字节赋值数据长度
-	pack_data[1] = datalen;
-
-	* pack_data_length = datalen + 2;
-}
-
-
 // 函数声明
 static void REGIST_Process(void); // 注册流程
 static void REGIST_SetStatus(enum REGIST_StatusEnum status); // 设置注册状态

+ 4 - 30
Drivers/Modules/ec800m/Ec800m_Regist.c

@@ -17,45 +17,19 @@
 
 #include "ec800m.h"
 
-// 泵号
-extern uint8_t mcu_id[8];
+
 // socket ID
 static uint8_t connectID = 2;
 
 // 注册参数
 static struct TUORENIOT_RegistRequestStruct regist_request = {
 	.version = 1,
-	.platform = "aliyun",
-	.networkProtocol = "CoAP",
+	.networkType = 2,
+	.networkProtocol = 1,
 	.deviceId = "3431228A1936013C",
-	.userId = 4562
+	.userId = "1000"
 };
 
-
-/**
-* 
-*注册参数信息打包
-*/
-void TUORENIOT_PackRegistRequest(uint8_t * pack_data, uint16_t * pack_data_length, struct TUORENIOT_RegistRequestStruct * registParams)
-{
-	
-	Log_Printf_Debug("mcu_id: %s\r\n", mcu_id);
-	// 设置deviceId
-	bytesToHex(registParams->deviceId, mcu_id, sizeof(mcu_id));
-	
-	sprintf((char *)(pack_data + 2), "{\"platform\":\"%s\",\"connectionType\":\"%s\",\"deviceId\":\"%s\"}", 
-	registParams->platform, registParams->networkProtocol, registParams->deviceId); // 拼接AT指令
-	Log_Printf_Debug("%s\r\n", (char *)(pack_data + 2));
-	
-	uint16_t datalen = utils_aes128_ECB_base64_enc_with_length(regist_key, (pack_data + 2));
-	
-	pack_data[0] = datalen>>8;//头2个字节赋值数据长度
-	pack_data[1] = datalen;
-
-	* pack_data_length = datalen + 2;
-}
-
-
 // 函数声明
 static void REGIST_Process(void); // 注册流程
 static void REGIST_SetStatus(enum REGIST_StatusEnum status); // 设置注册状态

+ 12 - 1
Hardware/GPIOA.c

@@ -22,8 +22,19 @@ void GPIOA_Init(void)
 	GPIO_InitStructure.GPIO_Speed 	= GPIO_Speed_50MHz;	
 	GPIO_Init(GPIOA, &GPIO_InitStructure);
 	GPIO_ResetBits(GPIOA, GPIO_Pin_7); // nb윗됴
+	#endif
 	
-  #endif
+	#if  ESP32
+	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
+	GPIO_InitTypeDef GPIO_InitStructure;
+	GPIO_InitStructure.GPIO_Mode = 	GPIO_Mode_Out_PP;
+	GPIO_InitStructure.GPIO_Pin = 	DEEP_SLEEP_GPIO_Pin|LIGHT_SLEEP_GPIO_Pin;
+	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+	GPIO_Init(WAKE_GPIO, &GPIO_InitStructure);
+	
+	GPIO_ResetBits(WAKE_GPIO, DEEP_SLEEP_GPIO_Pin); // WiFi�金추多신윗됴
+	GPIO_SetBits(WAKE_GPIO, LIGHT_SLEEP_GPIO_Pin);	// WiFi풍金추多신윗멕
+	#endif
 }
 
 

+ 4 - 13
User/main.c

@@ -26,6 +26,7 @@
 #include "bc260y.h"
 #include "At_Module.h"
 
+
 // 6365736869303036
 uint8_t mcu_id[8] = "ceshi006";
 
@@ -49,10 +50,8 @@ int main(void)
 	OLED_ShowString(1, 1, "MS:");
 	
 	Log_Printf_Debug("1234\r\n");
-	
 	bytesToHex(ch, mcu_id, sizeof(mcu_id));
-	
-	
+
 	// 通讯流程初始化
 	PUMPBUSINESS_Init();
 	
@@ -64,8 +63,7 @@ int main(void)
 		{
 			time_clear(&timer);
 		}
-		
-		
+
 		// 注册接口使用方法
 		if(regist_flag == 0)
 		{
@@ -81,17 +79,10 @@ int main(void)
 			}
 			regist_flag = 1;
 		}
-		
-		
-			
-		
-		
-		
+
 		// 通讯流程处理
 		PUMPBUSINESS_ProcessHandle();
 		
-		
-		
 	}
 	
 }