segunda-feira, 23 de maio de 2022

SMARTCORE IoT com LOM204, NINA B302, NINA W106

 U-BLOX NINA B302 - BLE SCANNER
 U-BLOX NINA B302 - END DEVICE COM AHT10 + BUTTON + BORNER

 WISOL LoRa LOM204 - END DEVICE COM BME280 + BUTTON
 U-BLOX NINA W106 - WEB SERVER


O objetivo deste BLOG é mostrar aplicação envolvendo vários módulos IoT da SMARTCORE.


7 SOFTWARES DESENVOLVIDOS E 3 PLACAS 

LOM204 - KEIL C END DEVICE E MASTER

#define SENDER true //#define RECEIVER true #define MYDEBUG true //---------------------------------------------------------------------------- // Project Name : LoRa WAN //---------------------------------------------------------------------------- // File Name : Main.c //---------------------------------------------------------------------------- // Processor : STM32L071CZY WLCSP // Compiler : uVision V5.20.0.0 // RF Transceiver : SX1276 // Frequency : 917 ~ 928Mhz // Modulation : LoRa // Version : H/W(1.3), LIB(2.02) // Company : Seongji Industrial //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- // History // // DATE Author Version COMMENT // 2018/06/01 KSH,CYH V1.00 Start // 2018/07/31 KSH,CYH V1.01 Modify : AFA, LRW 5D,Select Channel Add : AU915, // 2018/08/01 KSH,CYH V1.01 Add cmd: Channel Mask, Rx Delay1, Data rate, Join Accept Delay1, Repeater support, Activation, ABP setting value // Modify : JOIN_START, API_MODE // 2019/11/07 KSH V2.02 Add cmd: save Fcnt, sw reset, bug fix //---------------------------------------------------------------------------- #define MAIN_C_ #include <stddef.h> #include <string.h> #include "stm32l0xx_hal.h" #include <math.h> #include "board.h" #include "Utilities.h" #include "misc.h" #include "process.h" #include "timer.h" #include "init.h" #include "timer.h" #include "main.h" #include "WISOL_API.h" #if defined (SENDER) #include "BMP280.h" extern uint8_t I2C_Read_Register(uint8_t device_adr, uint8_t internal_adr); extern void I2C_Write_Register(uint8_t device_adr, uint8_t internal_adr, uint8_t data); extern I2C_HandleTypeDef hi2c1; #endif //-------------------------------------------------------------------------------------------------- // Setting description for DEFINE // // LED3_TRX : Led3 lturns on at Tx/Rx // RS485_USE : RE pin control when using RS485 converter. //------------------------------------------------------------------------------------------------- #if defined (RS485_USE) uint8_t Rs485_en =1; #endif /** * Main application entry point. */ #if 0 // CLI command Modem mode //--------------------------------------------------------------------------------------------------------- // Example // This example is used to control with CLI command through UART with external CPU. // It is LoRa modem //--------------------------------------------------------------------------------------------------------- int main( void ) { Start_Init(); while( 1 ) { CLI_MODE(); // LoRa Protocol is executed by going through an infinite loop. } } #endif #if 0 // RF Test Modem mode //--------------------------------------------------------------------------------------------------------- // Example // This example is used to control with CLI command through UART with external CPU. // It is for RF test ( To product, To certify ) //--------------------------------------------------------------------------------------------------------- extern void RFTEST_MODE( void ); int main( void ) { Start_Init(); while( 1 ) { RFTEST_MODE(); // LoRa Protocol is executed by going through an infinite loop. } } #endif #if 0 // API mode //--------------------------------------------------------------------------------------------------------- // Example // This example is used to control with CLI command through UART with external CPU. // It is LoRa modem, This example is the same as using CLI_MODE function //--------------------------------------------------------------------------------------------------------- int main(void){ uint8_t status_res; uint8_t *str1="900000100000010B"; Start_Init(); setOtaaAppEUI(str1,16); setClass( 0 ); // Set CLASS A mode. JOIN_START(); // Join srart // This function calls not only OTAA but also ABP while(1) { CLI_Command_Process(); // To receive CLI command through serial port(UART) status_res = API_MODE(); // Run LoRa protocol. if(status_res==API_DONE) { Enable_enter_stop_mode(); Device_State_Sleep_Fn(); // GPIO/TImer event check. Enter sleep mode at CLASS A Alarm_GPIO_Wakeup_Fn(); // When a timer alarm or a GPIO interrupt occurs, It allows the event to be processed. } else if(status_res== API_FAIL) { // send retry tx or enter sleep. // When using CLI_MODE function, enter sleep mode } } } #endif #if 0 // API mode Class C //--------------------------------------------------------------------------------------------------------- // Example // CLASS C mode, // After data transmission , enter receive mode. // The user function sets the UART communication baudrate by reading the external pin ( PB10, PB11 : 00 (9600bps) , 01:(19200bps), 10:(38400bps), 11:(115200bps)) //--------------------------------------------------------------------------------------------------------- void LED3_BLINK(void) { if(IO_OUT.BIT3==0) Set_BIT3(); else Clr_BIT3(); } int main(void) { Start_Init(); setClass( 2 ); // Set CLASS C mode. JOIN_START(); // Join srart // This function calls not only OTAA but also ABP Timer_1ms_Start(TRX_LED,300,6,LED3_BLINK); // LED3 blink 3times after join while(1) { CLI_Command_Process(); // To receive CLI command through serial port(UART) API_MODE(); // Run LoRa protocol. Device_State_Sleep_Fn(); // GPIO/TImer event check. Enter sleep mode at CLASS A } } #endif #if 0 // CLI command Modem mode //--------------------------------------------------------------------------------------------------------- // Example // Can selet CLASS A/C mode, // The user function sets the UART communication baudrate by reading the external pin ( PB10, PB11 : 00 (9600bps) , 01:(19200bps), 10:(38400bps), 11:(115200bps)) //--------------------------------------------------------------------------------------------------------- void User_fn(void) { uint8_t input_baud; input_baud =0; if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_10)==1) { input_baud |= 0x01; } if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_11)==1) { input_baud |= 0x02; } switch( input_baud ) { case 0 : setDebugMessage(0); setUartBaudRate( 9600); break; case 1 : setUartBaudRate( 19200); break; case 2 : setUartBaudRate( 38400); break; case 3 : setUartBaudRate( 115200 ); break; default : setUartBaudRate( 38400); break; } GpioInit( &IN_1, INPUT_1, PIN_INPUT, PIN_PUSH_PULL, PIN_PULL_DOWN, 0 ); GpioInit( &IN_2, INPUT_2, PIN_INPUT, PIN_PUSH_PULL, PIN_PULL_DOWN, 0 ); #if defined (RS485_USE) if( HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14)==1) { Rs485_en = 1; } else { Rs485_en = 0; } #endif } //--------------------------------------------------------------------------------------------------------- // Example // This example is used to control with CLI command through UART with external CPU. // It is LoRa modem //--------------------------------------------------------------------------------------------------------- int main( void ) { Start_Init(); User_fn(); while( 1 ) { CLI_MODE(); // LoRa Protocol is executed by going through an infinite loop. } } #endif #if 0 //--------------------------------------------------------------------------------------------------------- // Example // CLASS A mode, . // After data transmission , enter low power run mode. // The user function sets the UART communication baudrate by reading the external pin ( PB10, PB11 : 00 (9600bps) , 01:(19200bps), 10:(38400bps), 11:(115200bps)) //--------------------------------------------------------------------------------------------------------- // Pwr_State : 0 : enable entern stop mode // 1 : normal run // 2 : emable Low power run // 3: Low power run state int main(void) { uint8_t status_res; Pwr_Mode = LOW_POWER_RUN_MODE; // In CLASS A mode, enter low power run mode after completion of transmission and reception. default : SLEEP_MODE Start_Init(); setClass( 0 ); // Set CLASS A mode. JOIN_START(); // Join srart // This function calls not only OTAA but also ABP while(1) { CLI_Command_Process(); // To receive CLI command through serial port(UART) status_res = API_MODE(); // Run LoRa protocol. if(status_res==API_DONE) { // Enable_enter_lprun_mode(); // KSH 190813 Device_State_Sleep_Fn(); // GPIO/TImer event check. Enter sleep mode at CLASS A } else if(status_res== API_FAIL) { // send retry tx or enter sleep. // When using CLI_MODE function, enter sleep mode } } } #endif #if 0 //--------------------------------------------------------------------------------------------------------- // Example // CLASS A mode, Confirmed up data(1234567890) transfer every 20 seconds. // After data transmission , enter sleep mode. // Run User_fn function when waking up. // Get Device EUI and Print //--------------------------------------------------------------------------------------------------------- void User_fn(void) { } int main(void) { uint8_t* ipp; Start_Init(); setClass( 0 ); // Set CLASS A mode. JOIN_START(); // Join srart // This function calls not only OTAA but also ABP while(1) { CLI_Command_Process(); // To receive CLI command through serial port(UART) data_Tx(1,1,1,10,"1234567890"); // ASCII , Confirmed up, Fport : 1 , datalength : 10, data: 1234567890 API_MODE(); // Run LoRa protocol. Wakeup_Timer(&TxUser,User_fn,20000,0U); // It wakes up every 20 seconds and runs User_fn. Enable_enter_stop_mode(); // Setting condition for entry into sleep mode. Device_State_Sleep_Fn(); // GPIO/TImer event check. Enter sleep mode at CLASS A ipp = getDeviceEUI(); // get device EUI PRINTF("DEVEUI=0x"); // print device EUI for(uint8_t i=0; i<8; i++) { PRINTF("%02x",ipp[i]); } PRINTF("\r\n"); } } #endif #if 0 //--------------------------------------------------------------------------------------------------------- // Example // CLASS C mode, Confirmed up data(1234567890) transfer every 60 seconds. // When the message is received , Check message and print . // Run User_fn function when waking up. //--------------------------------------------------------------------------------------------------------- uint8_t tx_flag=0; void User_fn(void) { tx_flag =1; } void Exe_user_fn(void) { if( tx_flag ==1) { tx_flag =0; data_Tx(1,1,1,10,"1234567890"); // Tx data (ASCII , Confirmed up, Fport : 1 , datalength : 10, data: 1234567890 ) Wakeup_Timer(&TxUser,User_fn,60000,0U); // Wakes up every 60 seconds and runs User_fn. } } int main(void) { Start_Init(); setClass( 2 ); // Set CLASS C mode. JOIN_START(); // Join srart // This function calls not only OTAA but also ABP Wakeup_Timer(&TxUser,User_fn,60000,0U); // Wakes up every 60 seconds and runs User_fn. while(1) { CLI_Command_Process(); // To receive CLI command through serial port(UART) API_MODE(); // Run LoRa protocol. Exe_user_fn(); // execute user function if( Check_Received_Msg()) // Check for received messages. // return value : 1 [SUCCESS], 2: [FAIL], 0: No messages received. { PRINTF("PORT: %d\r\n",rx_msg.port); // Get the port of the received message. PRINTF("RX_MSG : "); for(uint8_t i =0; i<rx_msg.payload_size; i++) { PRINTF("%02x", rx_msg.mac_payload[i]); // Get the payload of the received message. } PRINTF("\r\n"); } // Do not clear or modify data of rx_msg . // When the data is received, rx_msg is updated // Message waiting status. } } #endif #if 0 // Write EEPROM data for user //--------------------------------------------------------------------------------------------------------- // Example // CLASS A mode, Read or write data eeprom.test1, eeprom.test2[16] at eeprom every 20 seconds. // //--------------------------------------------------------------------------------------------------------- uint8_t eeprom_cnt=0; uint8_t prt_flag=0; typedef struct _LORA_EEPROM_tag { uint32_t test1; uint8_t test2[16]; } lora_eeprom_t; lora_eeprom_t eeprom; void User_fn(void) { prt_flag =1; } void exe_user_fn(void) { prt_flag = 0; if(eeprom_cnt == 0) { nvm_write_user(NVM_USER + offsetof(lora_eeprom_t, test1),(void *)(&eeprom.test1), 4 ); // NVM_USER Address: 0x08080800 nvm_write_user(NVM_USER + offsetof(lora_eeprom_t, test2), (void *)(&eeprom.test2[0]), 16 ); } else { nvm_read_user(NVM_USER + offsetof(lora_eeprom_t, test1), (void *)(&eeprom.test1), 4 ); nvm_read_user(NVM_USER + offsetof(lora_eeprom_t, test2), (void *)(&eeprom.test2[0]), 16); PRINTF("test1 = %d, test2=",eeprom.test1); for(uint8_t i =0; i<16; i++) { PRINTF("%02x", eeprom.test2[i]); } PRINTF("\r\n"); } eeprom_cnt++; } int main( void ) { Start_Init(); setClass( 0 ); // Set CLASS A mode. JOIN_START(); // Join srart // This function calls not only OTAA but also ABP eeprom.test1 = 12; for(uint8_t i =0; i<16; i++) { eeprom.test2[i] = 0x30+i; } User_fn(); while( 1 ) { CLI_Command_Process(); // To receive CLI command through serial port(UART) API_MODE(); // Run LoRa protocol. Wakeup_Timer(&TxUser,User_fn,20000,0U); // Run User_fn every 20 seconds Enable_enter_stop_mode(); // Setting condition for entry into sleep mode. Device_State_Sleep_Fn(); // GPIO/TImer event check. Enter sleep mode at CLASS A Alarm_GPIO_Wakeup_Fn(); // When a timer alarm or a GPIO interrupt occurs, It allows the event to be processed. if( prt_flag !=0 ) { exe_user_fn(); } } } #endif #if 0 //--------------------------------------------------------------------------------------------------------- // Example // This example turns the LED on at the start and tnen it turns the LED off // if the join is complited, turns the LED on or off each time you send a message. // CLASS A mode //--------------------------------------------------------------------------------------------------------- void LED2_OFF(void); uint8_t led_flag =1; void LED2_OFF(void) { if(led_flag ==1) { GpioWrite( &Led2, 0 ); led_flag =0; } else { GpioWrite( &Led2, 1 ); led_flag =1; } } int main(void) { Start_Init(); setClass( 0 ); // Set CLASS A mode. GpioWrite( &Led2, 1 ); JOIN_START(); // Join srart while( 1 ) { LED2_OFF(); // Turn on and off the LED. CLI_Command_Process(); // To receive CLI command through serial port(UART) API_MODE(); Alarm_GPIO_Wakeup_Fn(); // When a timer alarm or a GPIO interrupt occurs, It allows the event to be processed. // Run LoRa protocol. Enable_enter_stop_mode(); // Setting condition for entry into sleep mode. Device_State_Sleep_Fn(); // GPIO/TImer event check. Enter sleep mode at CLASS A Alarm_GPIO_Wakeup_Fn(); // When a timer alarm or a GPIO interrupt occurs, It allows the event to be processed. } } #endif #if 0 //--------------------------------------------------------------------------------------------------------- // Example // This example turns on LED at start and turns off LED 500ms later // if the join is complited, the LED turns on or off each time you send a message. // CLASS A mode // The activation mode sets to ABP // for LIB ver 1.01 //--------------------------------------------------------------------------------------------------------- void LED1_OFF(void); uint8_t led_flag =1; void LED1_OFF(void) { if(led_flag ==1) { GpioWrite( &Led1, 0 ); led_flag =0; } else { GpioWrite( &Led1, 1 ); led_flag =1; } } int main(void) { uint8_t ret; Start_Init(); setClass( 0 ); // Set CLASS A mode. if( getActivation()==0 ) // If the current mode is OTAA. { setActivation(1); // set abp mode , If this function is run, module is reseted. } ret=setAbpDeviceAddress(0xed550001); PRINTF("\r\nret=%d\r\n",ret); ret=setAbpNwkSKey ( (unsigned char *) "11111111111111111111111111111111", 32 ); PRINTF("\r\nret=%d\r\n",ret); GpioWrite( &Led1, 1 ); Wakeup_Timer(&TxUser,LED1_OFF,500,0U); // Wakes up every 500ms and runs User_fn. JOIN_START(); // Join srart while( 1 ) { LED1_OFF(); // Turn on and off the LED. CLI_Command_Process(); // To receive CLI command through serial port(UART) API_MODE(); Alarm_GPIO_Wakeup_Fn(); // When a timer alarm or a GPIO interrupt occurs, It allows the event to be processed. // Run LoRa protocol. Enable_enter_stop_mode(); // Setting condition for entry into sleep mode. Device_State_Sleep_Fn(); // GPIO/TImer event check. Enter sleep mode at CLASS A Alarm_GPIO_Wakeup_Fn(); // When a timer alarm or a GPIO interrupt occurs, It allows the event to be processed. } } #endif #if defined (P2P) //SLAVE #if 1 // You need a P2P define //--------------------------------------------------------------------------------------------------------- // Example // This example shows how to use the P2P function to send a message or command // for LIB ver 1.01 //--------------------------------------------------------------------------------------------------------- extern uint8_t ProductState; extern uint8_t Uart_Rx_buff[272]; #if defined (SENDER) uint8_t Button; #endif #if defined (SENDER) // Send ASCII data unsigned char Buff[32]; #if defined (SENDER) char string[200]; #endif #if defined (SENDER) /** * @brief I2C MSP Initialization * This function configures the hardware resources used in this example * @param hi2c: I2C handle pointer * @retval None */ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(hi2c->Instance==I2C1) { /* USER CODE BEGIN I2C1_MspInit 0 */ /* USER CODE END I2C1_MspInit 0 */ __HAL_RCC_GPIOB_CLK_ENABLE(); /**I2C1 GPIO Configuration PB9 ------> I2C1_SDA PB8 ------> I2C1_SCL */ GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_8; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Peripheral clock enable */ __HAL_RCC_I2C1_CLK_ENABLE(); /* USER CODE BEGIN I2C1_MspInit 1 */ /* USER CODE END I2C1_MspInit 1 */ } } /** * @brief I2C1 Initialization Function * @param None * @retval None */ static void MX_I2C1_Init(void) { /* USER CODE BEGIN I2C1_Init 0 */ /* USER CODE END I2C1_Init 0 */ /* USER CODE BEGIN I2C1_Init 1 */ /* USER CODE END I2C1_Init 1 */ hi2c1.Instance = I2C1; hi2c1.Init.Timing = 0x40011A22; hi2c1.Init.OwnAddress1 = 0; hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; hi2c1.Init.OwnAddress2 = 0; hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK; hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; if (HAL_I2C_Init(&hi2c1) != HAL_OK) { //Error_Handler(); } /** Configure Analogue filter */ if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK) { //Error_Handler(); } /** Configure Digital filter */ if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK) { //Error_Handler(); } /* USER CODE BEGIN I2C1_Init 2 */ /* USER CODE END I2C1_Init 2 */ } /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ uint8_t string_compare(char array1[], char array2[], uint16_t lenght) { uint8_t comVAR=0, i; for(i=0;i<lenght;i++) { if(array1[i]==array2[i]) comVAR++; else comVAR=0; } if (comVAR==lenght) return 1; else return 0; } // reverses a string 'str' of length 'len' void reverse(char *str, int len) { int i=0, j=len-1, temp; while (i<j) { temp = str[i]; str[i] = str[j]; str[j] = temp; i++; j--; } } // Converts a given integer x to string str[]. d is the number // of digits required in output. If d is more than the number // of digits in x, then 0s are added at the beginning. int intToStr(int x, char str[], int d) { int i = 0; while (x) { str[i++] = (x%10) + '0'; x = x/10; } // If number of digits required is more, then // add 0s at the beginning while (i < d) str[i++] = '0'; reverse(str, i); str[i] = '\0'; return i; } // Converts a floating point number to string. void ftoa(float n, char *res, int afterpoint) { unsigned char minus_flag = 0; if(n<0) { minus_flag = 1; n = -n; } // Extract integer part int ipart = (int)n; // Extract floating part float fpart = n - (float)ipart; // convert integer part to string int i = intToStr(ipart, res, 0); // check for display option after point if (afterpoint != 0) { res[i] = '.'; // add dot // Get the value of fraction part upto given no. // of points after dot. The third parameter is needed // to handle cases like 233.007 fpart = fpart * pow(10, afterpoint); intToStr((int)fpart, res + i + 1, afterpoint); } char string[30]; if(minus_flag==1) { memset(string, 0, 30); string[0]='-'; if(n<1.0f) { string[1]='0'; strcpy(&string[2], res); }else strcpy(&string[1], res); memset(res, 0, strlen(res)); strcpy(res, string); }else if(n<1.0f) { string[0]='0'; strcpy(&string[1], res); memset(res, 0, strlen(res)); strcpy(res, string); } } /* USER CODE END 0 */ #endif void p2p_send(void) { //PA3 (BUTTON) // Send the message BMP280_calc_values(); memset(&string, 0, strlen(string)); strcat(string, "T"); ftoa(temperature-2, &string[strlen(string)], 3); //???? ajuste ??? sprintf(Buff, "%s %d %s\r\n","AT+LORA_MSGW=1,S", HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_10),string); P2P_AT_CMD(Buff);// Add \r\n\0 to the end of the data } #endif void p2p_cmd_send(void) { P2P_AT_CMD("AT+LORA_S=\r\n\0"); // Add \r\n\0 to the end of the data } int counter = 0; char led_flag = 0; int main(void) { Start_Init(); P2P_Init(); #if defined (SENDER) MX_I2C1_Init(); BMP280_init(); BMP280_calc_values(); init_height=altitude; #endif #if defined (SENDER) GpioInit( &IN_1, INPUT_1, PIN_INPUT, PIN_PUSH_PULL, PIN_PULL_UP, 0 ); //PB10 #endif #if defined (SENDER) p2p_send(); // send message #endif #if defined (SENDER) do { counter++; if(counter==1) { counter=0; if(led_flag==0) { GpioWrite( &Led1, 0 ); //apaga led1 led_flag = 1; } else { GpioWrite( &Led1, 1 ); //acende led1 led_flag = 0; } } #if defined (MYDEBUG) BMP280_calc_values(); memset(&string, 0, strlen(string)); strcat(string, "Temperature: "); ftoa(temperature, &string[strlen(string)], 3); strcat(string, " C\n"); strcat(string, "Pressure: "); ftoa(pressure, &string[strlen(string)], 3); strcat(string, " Pa\n"); strcat(string, "Altitude: "); ftoa(altitude, &string[strlen(string)], 3); strcat(string, " m\n"); strcat(string, "Relative altitude: "); ftoa(altitude-init_height, &string[strlen(string)], 3); strcat(string, " m\n\n\n"); PRINTF("%s",string); #endif CLI_Command_Process(); // To teceive commands via UART P2P_MODE(); // P2P process. This function is set to RX mode in idle state. if(Check_P2P_TX_Done()) // Use this command only after you send data wirelessly. { p2p_send(); } #if defined (SENDER) HAL_Delay(2000); //// comente para receber #endif }while(true); #endif #if defined (RECEIVER) do { counter++; if(counter==60000) { counter=0; if(led_flag==0) { GpioWrite( &Led1, 0 ); //apaga led1 led_flag = 1; } else { GpioWrite( &Led1, 1 ); //acende led1 led_flag = 0; } } CLI_Command_Process(); // To teceive commands via UART P2P_MODE(); // P2P process. This function is set to RX mode in idle state. }while(1); #endif } #endif #if 0 // You need a P2P define //--------------------------------------------------------------------------------------------------------- // Example // This example shows how to use the P2P function to receive a message // The rf_rx structure has received message information // for LIB ver 1.01 //--------------------------------------------------------------------------------------------------------- typedef struct RF_RXBUFFER { uint8_t id; uint8_t sn[4]; uint8_t bin; uint8_t data_size; uint8_t data[250]; }RF_RXBUF; extern RF_RXBUF rf_rx; //MASTER int main(void) { Start_Init(); P2P_Init(); do { CLI_Command_Process(); // To teceive commands via UART P2P_MODE(); // P2P process. This function is set to RX mode in idle state. if(Check_P2P_Rx_Msg()) // If rececive data is. { PRINTF("ID : %d\r\n",rf_rx.id); PRINTF("SN : 702C1F%X%X%X\r\n",rf_rx.sn[1],rf_rx.sn[2],rf_rx.sn[3]); // rf_rx.sn[0] = 0xFE PRINTF("data = %s\r\n",rf_rx.data); // print rx data } }while(1); } #endif #if 0 // You need a P2P define //--------------------------------------------------------------------------------------------------------- // Example // This example shows how to use the P2P function to send a message or command // Send ASCII message, Send Command, Send binary message // for LIB ver 1.01 //--------------------------------------------------------------------------------------------------------- extern uint8_t ProductState; extern uint8_t Uart_Rx_buff[272]; // Send ASCII data void p2p_send(void) { // Send the message twice P2P_AT_CMD("AT+LORA_MSGW=2,12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n\0");// Add \r\n\0 to the end of the data } // Send binary data void p2p_bin_send(void) { // data size : 0x03 // data : 0xAA 0xEE 0xFF // checksum : 0xBB uint8_t str[]={0x41,0x54,0x2B,0x42,0x49,0x4E,0x57,0x3D,0x03,0xAA,0xEE,0xFF,0xBB,0x0D,0x0A,0x00};// Add 0x0D 0x0A 0x00 to the end of the data P2P_AT_CMD(str); } void p2p_cmd_send(void) { P2P_AT_CMD("AT+LORA_S=\r\n\0"); // Add \r\n\0 to the end of the data } int main(void) { uint8_t i=0; Start_Init(); P2P_Init(); p2p_send(); // send message do { CLI_Command_Process(); // To teceive commands via UART P2P_MODE(); // P2P process. This function is set to RX mode in idle state. if(Check_P2P_TX_Done()) // Use this command only after you send data wirelessly. { switch(i) { case 0 : p2p_bin_send(); break; case 1 : p2p_cmd_send(); break; default : break; } i++; } }while(1); } #endif #endif // P2P void Start_Init(void) { HW_SystemClock_Config(); StartNVInit(); BoardInitPeriph( ); BoardInitMcu( ); Var_Init(); sub_process_init(); // set receive mode for uart #ifdef DEBUG_GPIO Timer_1ms_Start(IDLE_MODE_TIME_OUT,200,0xff,BIT0_fn); // When a module enters sleep, it no longer works. #endif TimerInit( &TxNext, Txnext_fn ); // Do not modify /* #if defined (USE_BAND_920) #ifndef OLD_CLI_COMPATIBILITY_MODE TimerInit( &Rest_send, restrict_send); #endif #endif */ nvm_init(); // To read the configuration saved in EEPROM. Clr_BIT2(); LDO_on(); } void Restart_Init(void) { BoardInitPeriph( ); BoardInitMcu( ); Var_Init(); sub_process_init(); // set receive mode for uart #ifdef DEBUG_GPIO Timer_1ms_Start(IDLE_MODE_TIME_OUT,200,0xff,BIT0_fn); // When a module enters sleep, it no longer works. #endif TimerInit( &TxNext, Txnext_fn ); // Do not modify /* #if defined (USE_BAND_920) #ifndef OLD_CLI_COMPATIBILITY_MODE TimerInit( &Rest_send, restrict_send); #endif #endif */ nvm_init(); // To read the configuration saved in EEPROM. Clr_BIT2(); LDO_on(); }

W106 - ANNEX BASIC -WEB SERVER

mac_addr_1$ = "XX:XX:XX:XX:XX:XX" mac_addr_2$ = "XX:XX:XX:XX:XX:XX" temp_2$= "XX.XX" led_1 = 0 led_2 = 0 print "Ram Available "; ramfree serial2.mode 921600, 22, 19 ' set serial port #2 to 115200 pin 22 TX, pin 19 RX PIN.MODE 15, OUTPUT PIN.MODE 5, OUTPUT PIN.MODE 4, OUTPUT PIN.MODE 21, OUTPUT PIN(15)= 0 'IO32 PIN(5)=0 'IO29 PIN(21)=0 'IO8 'RESET (B302 SCAN) PIN(4)=1 'IO24 PAUSE 100 PIN(4)=0 'IO24 PAUSE 100 PIN(4)=1 'IO24 'each 60000 seconds reset the NINA B302 scanner timer0 60000, reset 'each 60000 seconds reset the NINA B302 scanner timer1 1000, alive onserial2 rec2 onserial rec1 CLS 'HTML TEXTBOX$(mac_addr_1$) HTML replace$(textbox$(mac_addr_1$), ">", "size='40'>") HTML LED$(led_1) HTML replace$(textbox$(mac_addr_2$), ">", "size='40'>") HTML LED$(led_2) wait 'reset B302 (SCANNER) reset: 'RESET (B302 SCAN) PIN(4)=1 'IO24 PAUSE 100 PIN(4)=0 'IO24 PAUSE 100 PIN(4)=1 'IO24 return 'alive alive: PIN(21) = 1 - PIN(21) REFRESH return 'ID : 01 , SN : FEEE8C64 S 0 rec1: dat_1$ = serial.input$ 'HTML dat_1$ 'HTML len(dat_1$) if(len(dat_1$) >= 30) then PIN(5) = 1 - PIN(5) mac_addr_2$ = dat_1$ txt$ = LEFT$(dat_1$,21) txt$ = MID$(txt$,20,1) 'button led_2 = val(txt$) 'HTML dat_1$ 'HTML led_2 PIN(5) = 1 - PIN(5) 'REFRESH endif return rec2: dat$ = serial2.input$ 'HTML dat$ 'HTML " " 'HTML len(dat$) PIN(15) = 1 - PIN(15) mac_addr_1$ = dat$ txt2$= mid$(dat$,21,1) led_1 = 1 - val(txt2$) 'PULLUP NO LOM204 PIN(15) = 1 - PIN(15) 'REFRESH return




B302 - JAVASCRIPT - SCANNER

//variavel on com valor inicial ON var on = false; var on_state = false; //console.log("Hello World"); //First Function to execute during the BOOT function onInit() { // Start scanning Serial1.setup(921600, {rx:D29, tx:D45}); //Serial1.print("NINA B302 BLE SCAN ON"); //GPIO2 setInterval(function() { D14.write(on_state); on_state = !on_state; }, 1000); NRF.setScan(function(d) { //NINA B302 ENDDEVICE COM AHT10 //SE ACHOU, MANDA PARA O WEB SERVER - NINA W106 //if(d.id.includes("f2:52:f4:64:fd:9b")) { on = !on; //escreve no D13 D13.write(on); //GPIO 1 //console.log(d.id); //console.log(d.data); Serial1.print(d.id.substring(0,17)+ " S "+d.data[11]+" T"+d.data[9]+"."+d.data[10]+" "+String(d.data[12]*256+d.data[13])+" "+String(d.data[14]*256+d.data[15])+" "+String(d.data[16]*256+d.data[17])); //Transmite tudo de uma vez para nao enviar CR antes on = !on; //escreve no D13 D13.write(on); //GPIO 1 } }, { filters: [{ manufacturerData:{0x0591:{}} }] }); } /* //REMOVER DEPOIS Serial1.setup(921600, {rx:D29, tx:D45}); Serial1.print("NINA B302 BLE SCAN ON"); //GPIO2 setInterval(function() { D14.write(on_state); on_state = !on_state; }, 1000); NRF.setScan(function(d) { //NINA B302 ENDDEVICE COM AHT10 //SE ACHOU, MANDA PARA O WEB SERVER - NINA W106 //if(d.id.includes("f2:52:f4:64:fd:9b")) { on = !on; //escreve no D13 D13.write(on); //GPIO 1 //console.log(d.id); //console.log(d.data); Serial1.print(d.id.substring(0,17)+ " S "+d.data[11]+" T"+d.data[9]+"."+d.data[10]+" "+String(d.data[12]*256+d.data[13])+" "+String(d.data[14]*256+d.data[15])+" "+String(d.data[16]*256+d.data[17])); //Transmite tudo de uma vez para nao enviar CR antes on = !on; //escreve no D13 D13.write(on); //GPIO 1 } }, { filters: [{ manufacturerData:{0x0591:{}} }] }); */


































B302 - JAVASCRIPT - SCANNER

//variavel on com valor inicial ON var on = false; var on_state = false; //console.log("Hello World"); //First Function to execute during the BOOT function onInit() { // Start scanning Serial1.setup(921600, {rx:D29, tx:D45}); //Serial1.print("NINA B302 BLE SCAN ON"); //GPIO2 setInterval(function() { D14.write(on_state); on_state = !on_state; }, 1000); NRF.setScan(function(d) { //NINA B302 ENDDEVICE COM AHT10 //SE ACHOU, MANDA PARA O WEB SERVER - NINA W106 //if(d.id.includes("f2:52:f4:64:fd:9b")) { on = !on; //escreve no D13 D13.write(on); //GPIO 1 //console.log(d.id); //console.log(d.data); Serial1.print(d.id.substring(0,17)+ " S "+d.data[11]+" T"+d.data[9]+"."+d.data[10]+" "+String(d.data[12]*256+d.data[13])+" "+String(d.data[14]*256+d.data[15])+" "+String(d.data[16]*256+d.data[17])); //Transmite tudo de uma vez para nao enviar CR antes on = !on; //escreve no D13 D13.write(on); //GPIO 1 } }, { filters: [{ manufacturerData:{0x0591:{}} }] }); } /* //REMOVER DEPOIS Serial1.setup(921600, {rx:D29, tx:D45}); Serial1.print("NINA B302 BLE SCAN ON"); //GPIO2 setInterval(function() { D14.write(on_state); on_state = !on_state; }, 1000); NRF.setScan(function(d) { //NINA B302 ENDDEVICE COM AHT10 //SE ACHOU, MANDA PARA O WEB SERVER - NINA W106 //if(d.id.includes("f2:52:f4:64:fd:9b")) { on = !on; //escreve no D13 D13.write(on); //GPIO 1 //console.log(d.id); //console.log(d.data); Serial1.print(d.id.substring(0,17)+ " S "+d.data[11]+" T"+d.data[9]+"."+d.data[10]+" "+String(d.data[12]*256+d.data[13])+" "+String(d.data[14]*256+d.data[15])+" "+String(d.data[16]*256+d.data[17])); //Transmite tudo de uma vez para nao enviar CR antes on = !on; //escreve no D13 D13.write(on); //GPIO 1 } }, { filters: [{ manufacturerData:{0x0591:{}} }] }); */

B302 - JAVASCRIPT - END DEVICE

/* Copyright (c) 2014 Gustav Karlström. See the file LICENSE for copying permission. */ /* Library for the sensor AHT10 https://wiki.liutyi.info/display/ARDUINO/AHT10 */ const i2c = new I2C(); const C = { ahtAddress: 0x38, sensorCalibrateCmd: [0xE1, 0x08, 0x00], sensorMeasureCmd: [0xAC, 0x33, 0x00], bytesInAMebibyte: 1048576, getRHCmd: true, getTempCmd: false, waterVapor: 17.62,//f barometricPressure: 243.5 //f }; function getRawSensorData(getDataCmd) { i2c.writeTo(C.ahtAddress, C.sensorMeasureCmd); const dataFromSensor = i2c.readFrom(C.ahtAddress, 6); if (getDataCmd) { return ((dataFromSensor[1] << 16) | (dataFromSensor[2] << 8) | dataFromSensor[3]) >> 4; } return ((dataFromSensor[3] & 0x0F) << 16) | (dataFromSensor[4] << 8) | dataFromSensor[5]; } function AHT10(scl, sda, bitrate) { this.scl = scl; this.sda = sda; this.bitrate = bitrate || 300000; i2c.setup({ scl: this.scl, sda: this.sda, bitrate: this.bitrate }); i2c.writeTo(C.ahtAddress, C.sensorCalibrateCmd); if ((i2c.readFrom(C.ahtAddress, 1) & 0x68) === 0x08) { console.log('Connection to AHT10 successful'); } else { console.log('Connection to AHT10 failed'); } } AHT10.prototype.getTemperature = function () { const rawData = getRawSensorData(C.getTempCmd); return ((200 * rawData) / C.bytesInAMebibyte) - 50; }; AHT10.prototype.getHumidity = function () { const rawData = getRawSensorData(C.getRHCmd); if (rawData === 0) { return 0; } return rawData * 100 / C.bytesInAMebibyte; }; AHT10.prototype.getDewPoint = function () { const humidity = this.getHumidity(); const temperature = this.getTemperature(); const gamma = Math.log(humidity / 100) + C.waterVapor * temperature / (C.barometricPressure + temperature); const dewPoint = C.barometricPressure * gamma / (C.waterVapor - gamma); return dewPoint; }; connect = function (scl, sda, bitrate) { return new AHT10(scl, sda, bitrate); }; var Button = 0; var Interval_To_Read_AHT10 = 0; var IO45; var IO44; var IO43; //variavel on com valor inicial ON var on = false; function GetAHT10() { setInterval(function() { //on = !on; UpdateAdv(); }, 2000); } var t; var h; var t_int; var t_float; var AD_IO20; var AD_IO23; var AD_IO24; var AD_IO20_msb; var AD_IO20_lsb; var AD_IO23_msb; var AD_IO23_lsb; var AD_IO24_msb; var AD_IO24_lsb; function UpdateAdv() { if(Interval_To_Read_AHT10 == 0) { sensor.getTemperature(); t = sensor.getTemperature(); t_int = Math.floor(t); t_float = Math.floor((t - t_int) * 100.0); } Interval_To_Read_AHT10++; if(Interval_To_Read_AHT10 == 4) //2 seconds Interval_To_Read_AHT10=0; //pull-up Button = !D2.read(); //Le estado do botao GPIO18 DO U-BLOX // {name:"Smartcore-" + NRF.getAddress()} AD_IO20 = analogRead(D31) * 1023.0; AD_IO23 = analogRead(D29) * 1023.0; AD_IO24 = analogRead(D30) * 1023.0; AD_IO20_msb = Math.round(AD_IO20 / 256); AD_IO20_lsb = Math.round(AD_IO20 % 256); AD_IO23_msb = Math.round(AD_IO23 / 256); AD_IO23_lsb = Math.round(AD_IO23 % 256); AD_IO24_msb = Math.round(AD_IO24 / 256); AD_IO24_lsb = Math.round(AD_IO24 % 256); IO45 = D7.read(); IO44 = D27.read(); IO43 = D6.read(); NRF.setAdvertising({},{ showName:false, connectable: true, scannable: true, manufacturer: 0x0591, manufacturerData:[0x00,0x00,t_int,t_float,Button,AD_IO20_msb,AD_IO20_lsb,AD_IO23_msb,AD_IO23_lsb,AD_IO24_msb,AD_IO24_lsb,IO45,IO44,IO43] }); } //First Function to execute during the BOOT function onInit() { console.log("Smartcore"); NRF.setTxPower(4); //cria função que é chamada a cada 100ms setInterval(function() { //inverte estado da variável ON on = !on; //escreve no D13 D13.write(on); //GPIO 1 }, 1000); sensor = connect(D3,D4); //GPIO16 E GPIO25 DO U-BLOX GetAHT10(); } //DIGITAL IO45 - D7 //ANALOG IO20 - D31 //ANALOG IO23 - D29 //ANALOG IO24 - D30 //DIGITAL IO44 - D27 //DIGITAL IO43 - D6
/* Copyright (c) 2014 Gustav Karlström. See the file LICENSE for copying permission. */ /* Library for the sensor AHT10 https://wiki.liutyi.info/display/ARDUINO/AHT10 */ const i2c = new I2C(); const C = { ahtAddress: 0x38, sensorCalibrateCmd: [0xE1, 0x08, 0x00], sensorMeasureCmd: [0xAC, 0x33, 0x00], bytesInAMebibyte: 1048576, getRHCmd: true, getTempCmd: false, waterVapor: 17.62,//f barometricPressure: 243.5 //f }; function getRawSensorData(getDataCmd) { i2c.writeTo(C.ahtAddress, C.sensorMeasureCmd); const dataFromSensor = i2c.readFrom(C.ahtAddress, 6); if (getDataCmd) { return ((dataFromSensor[1] << 16) | (dataFromSensor[2] << 8) | dataFromSensor[3]) >> 4; } return ((dataFromSensor[3] & 0x0F) << 16) | (dataFromSensor[4] << 8) | dataFromSensor[5]; } function AHT10(scl, sda, bitrate) { this.scl = scl; this.sda = sda; this.bitrate = bitrate || 300000; i2c.setup({ scl: this.scl, sda: this.sda, bitrate: this.bitrate }); i2c.writeTo(C.ahtAddress, C.sensorCalibrateCmd); if ((i2c.readFrom(C.ahtAddress, 1) & 0x68) === 0x08) { console.log('Connection to AHT10 successful'); } else { console.log('Connection to AHT10 failed'); } } AHT10.prototype.getTemperature = function () { const rawData = getRawSensorData(C.getTempCmd); return ((200 * rawData) / C.bytesInAMebibyte) - 50; }; AHT10.prototype.getHumidity = function () { const rawData = getRawSensorData(C.getRHCmd); if (rawData === 0) { return 0; } return rawData * 100 / C.bytesInAMebibyte; }; AHT10.prototype.getDewPoint = function () { const humidity = this.getHumidity(); const temperature = this.getTemperature(); const gamma = Math.log(humidity / 100) + C.waterVapor * temperature / (C.barometricPressure + temperature); const dewPoint = C.barometricPressure * gamma / (C.waterVapor - gamma); return dewPoint; }; connect = function (scl, sda, bitrate) { return new AHT10(scl, sda, bitrate); }; var Button = 0; var Interval_To_Read_AHT10 = 0; var IO45; var IO44; var IO43; //variavel on com valor inicial ON var on = false; function GetAHT10() { setInterval(function() { //on = !on; UpdateAdv(); }, 2000); } var t; var h; var t_int; var t_float; var AD_IO20; var AD_IO23; var AD_IO24; var AD_IO20_msb; var AD_IO20_lsb; var AD_IO23_msb; var AD_IO23_lsb; var AD_IO24_msb; var AD_IO24_lsb; function UpdateAdv() { if(Interval_To_Read_AHT10 == 0) { sensor.getTemperature(); t = sensor.getTemperature(); t_int = Math.floor(t); t_float = Math.floor((t - t_int) * 100.0); } Interval_To_Read_AHT10++; if(Interval_To_Read_AHT10 == 4) //2 seconds Interval_To_Read_AHT10=0; //pull-up Button = !D2.read(); //Le estado do botao GPIO18 DO U-BLOX // {name:"Smartcore-" + NRF.getAddress()} AD_IO20 = analogRead(D31) * 1023.0; AD_IO23 = analogRead(D29) * 1023.0; AD_IO24 = analogRead(D30) * 1023.0; AD_IO20_msb = Math.round(AD_IO20 / 256); AD_IO20_lsb = Math.round(AD_IO20 % 256); AD_IO23_msb = Math.round(AD_IO23 / 256); AD_IO23_lsb = Math.round(AD_IO23 % 256); AD_IO24_msb = Math.round(AD_IO24 / 256); AD_IO24_lsb = Math.round(AD_IO24 % 256); IO45 = D7.read(); IO44 = D27.read(); IO43 = D6.read(); NRF.setAdvertising({},{ showName:false, connectable: true, scannable: true, manufacturer: 0x0591, manufacturerData:[0x00,0x00,t_int,t_float,Button,AD_IO20_msb,AD_IO20_lsb,AD_IO23_msb,AD_IO23_lsb,AD_IO24_msb,AD_IO24_lsb,IO45,IO44,IO43] }); } //First Function to execute during the BOOT function onInit() { console.log("Smartcore"); NRF.setTxPower(4); //cria função que é chamada a cada 100ms setInterval(function() { //inverte estado da variável ON on = !on; //escreve no D13 D13.write(on); //GPIO 1 }, 1000); sensor = connect(D3,D4); //GPIO16 E GPIO25 DO U-BLOX GetAHT10(); } //DIGITAL IO45 - D7 //ANALOG IO20 - D31 //ANALOG IO23 - D29 //ANALOG IO24 - D30 //DIGITAL IO44 - D27 //DIGITAL IO43 - D6







IMAGENS



VÍDEO

NO VÍDEO FALTARAM OS ESTADOS DAS GPIOS DIGITAIS DO BORNER - MAS FOI ACRESCENTADO DEPOIS NO SOFTWARE


Sobre a SMARTCORE

A SmartCore fornece módulos para comunicação wireless, biometria, conectividade, rastreamento e automação.
Nosso portfólio inclui modem 2G/3G/4G/NB-IoT/Cat.M, satelital, módulos WiFi, Bluetooth, GNSS / GPS, Sigfox, LoRa, leitor de cartão, leitor QR code, mecanismo de impressão, mini-board PC, antena, pigtail, LCD, bateria, repetidor GPS e sensores.
Mais detalhes em www.smartcore.com.br

Nenhum comentário:

Postar um comentário