Jump to content

Gina

Beyond the Event Horizon
  • Posts

    45,326
  • Joined

  • Last visited

  • Days Won

    120

Everything posted by Gina

  1. Latest -trying to get wind instruments working. Mainly problems with the coding.
  2. Some of it seems to be working. Direction and Gust speed but not Mean speed.
  3. Wrong void loop() { if (!client.connected()) { reconnect(); } client.loop(); long now = millis(); if(now - last3s > P3s) {do3sJobs; last3s = now;} if(now - last1m > P1m) {do1mJobs; last1m = now;} if(now - last3m > P3m) {do3mJobs; last3m = now;} } Right - missed out the () in the doxxJobs calls. Doh!! void loop() { if (!client.connected()) { reconnect(); } client.loop(); long now = millis(); if(now - last3s > P3s) {do3sJobs(); last3s = now;} if(now - last1m > P1m) {do1mJobs(); last1m = now;} if(now - last3m > P3m) {do3mJobs(); last3m = now;} }
  4. Found the silly mistake!!!
  5. First test - sending the instantaneous wind direct every 3 seconds. void do3sJobs (){ sendDirectionMessage(readDirection()); // send instantaneous direction Later... NOT working - nothing!!! Have to try something simpler!
  6. Surprise, surprise - it doesn't work!! Guess I'm going to have to put debug messages in to see what's happening. Have it set up on the living room table. MQTT Explorer is not showing any of the 5 wind messages.
  7. Here is the speed and direction code. The sketch compiles fine but can't be sure I've got the maths right. void do3sJobs (){ windSpeed = ++PulseCount; // Accumulate mean speed if (PulseCount > windGust) {windGust = PulseCount;}; // Get max speed for gust PulseCount = 0; ++bin[readDirection()]; // increment appropriate bin } void do1mJobs(){ // wind speed mean and gust ring arrays and report meanArray[ringIndex] = windSpeed; // put windSpeed into new array index gustArray[ringIndex] = windGust; // put windGust into new array index // windSpeed /=20; // leave this for later for (int i = 0; i < 10; i++) { meanSpeed += meanArray[i]; // add all windSpeeds if (gustArray[i] > gustSpeed){gustSpeed = gustArray[i];}; // find maximum gust speed } meanSpeed /=200; // the first sum was over 20 values and then the second over 10 values sendSpeedMessages(); windGust = 0; ringIndex = (ringIndex+1)%10; // move ringIndex on to next location in the ring array } void do3mJobs(){ // wind direction calculations and report int sum[16]; int S=0,I=0,W=0; bin[16] = bin[0]; bin[17] = bin[1]; bin[18] = bin[2]; bin[19] = bin[3]; for (int i = 0; i < 16; i++) { sum[i] = bin[i] + bin[i+1] + bin[i+2] + bin[i+3] + bin[i+4]; // find the index with the highest sum and save sum and index if (sum[i] > S){S = sum[i]; I = i;}; } W = (bin[I+1] + 2 * bin[I+2] + 3 * bin[I+3] + 4 * bin[I+4]) * 45 / S; sendDirectionMessage((I * 45 + W)%720 /2); } void loop() { if (!client.connected()) { reconnect(); } client.loop(); long now = millis(); if(now - last3s > P3s) {do3sJobs; last3s = now;} if(now - last1m > P1m) {do1mJobs; last1m = now;} if(now - last3m > P3m) {do3mJobs; last3m = now;} } May be able to test it tomorrow. That's it for tonight.
  8. Blummin' 'eck - so I did - must be getting tired. Thanks both.
  9. OK so can someone please tell me what I've done wrong here? Further up I have this // Direction count bins int bin[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; Maybe it doesn't like "bin"?
  10. Now looking at the Consensus Averaging. It's even more complicated than it looks! I don't think I shall be doing much more tonight.
  11. I shall need to clear the gustSpeed to zero each 1m period. That will still keep the earlier gust values in the ring array but allow it to go after 10m.
  12. I'm hoping this is right for the speed calculations void do3sJobs (){ windSpeed = ++PulseCount; // Accumulate mean speed if (PulseCount > windGust) {windGust = PulseCount;}; // Get max speed for gust PulseCount = 0; ++dirbinsArray[readDirection()]; // increment appropriate bin } void do1mJobs(){ // wind speed mean and gust ring arrays and report meanArray[ringIndex] = windSpeed; // put windSpeed into new array index gustArray[ringIndex] = windGust; // put windGust into new array index // windSpeed /=20; // leave this for later for (int i = 0; i < 10; i++) { meanSpeed += meanArray[i]; // add all windSpeeds if (gustArray[i] > gustSpeed){gustSpeed = gustArray[i];}; // find maximum gust speed } meanSpeed /=200; // the first sum was over 20 values and then the second over 10 values sendSpeedMessages(); ringIndex = (ringIndex+1)%10; // move ringIndex on to next location in the ring array }
  13. Think this should work :- void loop() { if (!client.connected()) { reconnect(); } client.loop(); long now = millis(); if(now - last3s > P3s) {do3sJobs; last3s = now;} if(now - last1m > P1m) {do1mJobs; last1m = now;} if(now - last3m > P3m) {do3mJobs; last3m = now;} if(now - last10m > P10m) {do10mJobs; last10m = now;} }
  14. Ah!! Thank you. That was it - compiles now. Pity the error didn't say that!
  15. Can anyone please tell me what's wrong here?
  16. I think I need to establish various intervals in void loop() and put the required data process in routines that are called at those intervals. 3s - get speed count and read direction 60s - get result of average and maximum of wind speed count - circulate in ring arrays and calculate rolling average and max 3m - process direction data and send message to MQTT 10m Not sure the 10m period is needed.
  17. I'm going to need to rethink the periods involved in the various counts and calculations. The Consensus Averaging I've been looking at uses 60 samples with 5s sampling and 5m period. If I were going to use 1m reporting, with 3s sampling that would only be 20 samples in each period. I don't think this is enough to give good results. If I were to use 3m integration period yet report every minute I would need 3 sets of bins and the functions that go with them. I think I might go for a 3m reporting period for wind direction. For the wind mean speed and gust speed, the gust integration period wants to be 3s as it already is. An integration period of 10m is recommended by the Met Office. A reporting period of 10m would be the easiest solution but I think I would prefer a more frequent report. I could go back to the 1m reporting period and 10m integration using a pair of 10 integer ring arrays - one for mean and one for gust speeds. The result of the above is that the reporting intervals are different for direction and speed.
  18. I was going to use a 2 dimensional array for the mean and gust ring array but it seems the Arduino IDE has the odd error with multi-dimensional arrays so I'll use two single dimension arrays.
  19. I'm not using a database yet. Also, I'm not familiar with Java and using C++ (Arduion IDE). I like a compiled language. I think I shall keep direction and speed data and functions separate as this aids debugging.
  20. @tekkydave that looks much like the same maths in a different language for the direction but also includes the speed. That's web page I'm using for the algorithm.
  21. I've been examining the Consensus Averaging procedure with my Mathematical Hat on and I understand all of it except the weighted sum. W = ( n(I+1) + 2 * n(I+2) + 3 * n(I+3) + 4 * n(I+4) ) * 45 / S I don't understand weighting the higher index "bins" higher. I would have thought a Gaussian shaped weighting would have been wanted rather than a linearly increasing weighting. If there are any maths experts around, I would be grateful for an explanation. However, the proof of the pudding... is that this method seems to work pretty well!! Thinking about it, I may just go for the method shown rather than out think it and use a ring array. After all "it ain't broke so don't try to fix it". 😁
  22. Regarding Consensus Averaging :- using a ring array of 16 integers. sum = n(i) + n(i+1) + n(i+2) + n(i+3) + n(i+4). Becomes sum = n(i) + n((i+1)%16) + n((i+2)%16) + n((i+3)%16) + n((i+4)%16) And W = ( n(I+1) + 2 * n(I+2) + 3 * n(I+3) + 4 * n(I+4) ) * 45 / S Becomes W = ( n((I+1)%16) + 2 * n((I+2)%16) + 3 * n((I+3)%16) + 4 * n((I+4)%16) ) * 45 / S I do wonder if this is more complicated (using more space and time) than just using a 20 integer array rather than 16. OTOH I think this is the more correct approach. I'm not sure that the results are going to be correct around the zero direction with 20 "bins" but I'm having difficulty getting my poor old brain round this complex maths. If the C++ (Arduino) language had nybble as a data type I could use that for the index since the modulo is 16 and save having to apply modulo. Whether %16 uses more resources than bit logic (&15) I don't know and doubt it makes much difference in this case but from my programming experience in many languages, bit logic is usually more sparing of resources.
  23. We get a lot of drizzle! Useful information on not what to buy though 😀 Thanks.
  24. I would like opinions and recommendations/experience of rain detectors that could be used to tell my roll-off-roof control to close the roof at the first drops of rain, please. I have the Kemo Rain Sensor 12 V/DC and considering the Hydreon RG-11 Optical Rain Sensor. I'm wondering if the Hydreon is better at detecting clean rain that sometimes fails to operate the Kemo.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.