/** ********************************************************************************** * WiFi Gateway Project 100MHz STM32-F411RE ********************************************************************************** * This project works as a wireless sensor receiver using a 433MHz receiver module. * The data is then sent to a Raspberry Pi using TCP/IP via a ESP8266 module. * System clock is 100MHz * * SysTick-counter is setup to handle the LED-flashing * The systick int is 1mS and it calles the LED-Handler * Systick is changed to the lowest possible priority * * TIM2 is set to sample the Rx-input in a 10uS period. TIM2_IRQHandler() * HW is set to 32 prescaler + 10 counter period * TIM2 also handles the micros()-functions, and counts mS in millis() * * TIM3 is not used * * The USART1 is used for comm to WiFi-module. Handled with interrupts. * * The USART2 is used for communicating to the ST/Link v2 as a simulated * USB Serial Port. This is handled with interrupts. * * Compiler options: Turned off common subexpression elimination. * If this on is one, then while-loop can be optimized away. Results in very * strange code. After this change, I could remove all volatile keywords. * * IO-Pins: * PA0 Input RX_DATA * PA5 Output GREEN_LED * * Notes: * Had one awful bug. It crashed into HardFault_Handler. The problem was found * after many hours on a forum. It was regarding string-functions which wrote to * a local stack-char-array belonging to a calling function ! Not fun ! * ********************************************************************************** */ #include #include #include "sw_fifo_1.h" #include "sw_fifo_2.h" #include "app.h" #include "led_blink.h" #include "main.h" #include "queue.h" #include "temp3.h" #include "stm32f4xx_hal.h" #include "stm32f4xx_hal_gpio.h" #include "wifi.h" #include "receiver.h" #include "interrupts.h" void printTime(); void setRTCTime(); extern RTC_HandleTypeDef hrtc; void setup() { printf("\n\n\n\n\n100MHz 433.92MHz to WiFi Gateway\n"); printf("--------------------------------\n\n"); deactivateESP8266(); // Turn off the WiFi-Board, ESP8266 rcvInitQueue(); wifi_rcvInitQueue(); setupWifi(); handle_RTC_interrupt(); setRTCTime(); printf("Init completed\n\n"); receiverEnabled = 1; } void printClock() { unsigned long time=millis(); printf("%lu,%lu",(time/1000),(time%1000)); } extern int sec,min,hour; void loop() { static int noOfCodesReceived=0; unsigned int type, value; int code; int retrys = 0; //receiver(); // This takes from the receive-function (in receiver.c) // And calls the WiFi-function to send data to the http-server while( wifi_rcvDeQueue( &type, &value) ) { switch( type ) { case 0: // Nexa printClock();printf(" \n\r",value); break; case 1: printClock();printf(" No 1:%u \n\n",value); break; case 2: printClock();printf(" No 2:%u \n\n",value); break; case 3: noOfCodesReceived++; printTime();printf(" No 3:%u ",value); code = (value & 0xFC000000) >> 26; printf("Code:%d \n\n",code); break; default: printf("Unknown type\n"); break; } if( type == 3 ) { // Send data to server while( retrys < 3 && sendDataToServer(type,value ) == 0 ) { retrys++; printf("********** ERROR **********\n"); setupWifi(); // We have run into problems.....need to reset WiFi-module } } } // Handle logging /* if( loggingReady == 1 ) { static char logTxtData[2000]; // CIP-Send-string is max 2048 bytes, according to ESP8266 Docs char str[20]; loggingReady = 0; int logItems = (startLoggingPos