print a blurb illustrating the order in which data was received head has been moved away from tail so there's data there Serial.println( "No new data received." ) if the head and tail are the same, there's no new data Here's an example of what I talked about: /* That way you have padding space in your buffer to accept new data while still processing older stuff. If you think the data is "bursty" - comes in rapidly in quick bursts - and you might get around to processing the data some time later, consider making the buffer bigger than the burst size. You should be able to process data in a buffer reasonably quickly. If so, you can have the buffer overrun problem you want to check and prevent that. So when incrementing the head pointer you need to verify it doing so would cause the head to catch up to the tail. If another byte comes in before you process the value pointed to by ptrTail you'll overwrite the value there and lose the "oldest" data in the buffer. You get a byte of data so array = data and you bump ptrHead now it becomes 8 because it equals the size of the array you reset its value back to zero. Suppose ptrHead equals 7 and ptrTail equals 0. You could use 4 if you know you'll process data as fast as it comes in. Make an array of size 'N' (in your case, N=4).Ĭreate two variables (uint8_t is fine as the array size is 0, 1, 2. The Queue defined is only 1 element long but you may add more queue elements as desired. } // void mqttCallback(char* topic, byte* payload, unsigned int length) XQueueOverwrite( xQ_Message, (void *) &x_message ) // send data to queue X_message.topic = topic //store new topic X_message.topic = "" //clear topic string buffer Memset( x_message.payload, '\0', 150 ) // clear payload char buffer Sending queue data void IRAM_ATTR mqttCallback(char* topic, byte * payload, unsigned int length) } // void fparseMQTT( void *pvParameters ) } //if ( xQueueReceive(xQ_Message, &px_message, portMAX_DELAY) = pdTRUE ) X_eData.RM0 = String(px_message.payload).toFloat() If ( px_message.topic = topicRemainingMoisture_0 ) XSemaphoreTake( sema_mqttOK, portMAX_DELAY ) If ( xQueueReceive(xQ_Message, &px_message, portMAX_DELAY) = pdTRUE ) wait 'forever' or until a message arrives in the queue Receiving queue data void fparseMQTT( void *pvParameters ) Setting up the Queue in setup() xQ_Message = xQueueCreate( 1, sizeof(stu_message) ) QueueHandle_t xQ_Message // payload and topic queue of MQTT payload and topic Global decleration include "freertos/FreeRTOS.h" If you have an ESP32 or a ESP8266 with OS, here is how to setup a FIFO queue and use a Queue. } //if ( xQueueReceive(xQ_lrData, &lrData, portMAX_DELAY) = pdTRUE ) log_i( "DoTheBME280Thing high watermark % d", uxTaskGetStackHighWaterMark( NULL ) ) Log_i( "Correlation: %f Values: Y=%f and *X + %f ", lr.Correlation(), values, values ) // correlation is the strength and direction of the relationship Calculate( tsUnit ) ) //calculate next time unit? TsUnit *= tsAtom //setting time units to the same scale TsUnit = TimeStamps - TimeStamps //get the time stamp quantity Lr.Data( tsMean, DataPoints - dpMean ) // train lr TsAtom = 1.0f / (TimeStamps - TimeStamps) // no need to do this part of the calculation every for loop ++ timestamp mean is ts * (1 / ts_Firstcell - ts_Lastcell). insert new data points and time stamp (ts) at the end of the data arrays shift datapoints collected one place to the left Log_i( "lrCount %d TimeStamp %f lrData %f", lrCount, TimeStamps, DataPoints ) TimeStamps = (float)xTaskGetTickCount() / 1000.0f If ( xQueueReceive(xQ_lrData, &lrData, portMAX_DELAY) = pdTRUE ) The variable magicNumber is the buffer size. Here I am using 2 arrays as a FIFO buffer to collect dat to be used in a Linear Regression formula to predict future readings.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |