The question is more about the quality of the data you acquire on the sender side.
here I can't see how the acquisition works. It would be interesting to check if the crazy values like 40,000 kg comes from reading the HX711, in which case there is no need to worry about the Lora transmission and the work would be about ensuring the acquisition does not fail.
Regarding the code, your bubble sort does work and I see how you are trying to get the median value taking into account how many samples were actually acquired - this feels in theory fine (you create a median value that was not really an acquired sample by taking the average when you have 2 and 4 samples but that's a design decision that sounds rational).
What does not work is that because the window array and the sortedArray are actually one and the same in memory, you have messed up the window array when you did the sorting.
The consequence is that when you store the new sample with window[indeks] = input; you are very likely overwriting a previous value and not keeping a rolling window for the last 5 samples.
➜ you need a real copy of the array and not just a pointer. I would change this code
// sort the values in the window:
float* sortedArray = window;
mySort(sortedArray, 5);
into
// sort the values in a copy of the window:
float sortedArray[5]; // it would be good to make 5 a global constant and use the constant everywhere instead of the magic value 5
for (byte i = 0; i < 5; i++) sortedArray[i] = window[i];
mySort(sortedArray, 5);
Your existing code could lead to wrong median values but as the array is a global variable, it's initialized with 0 values and then you fill it up with real samples (even when you overwrite an existing one) the median would not go to crazy high values. So it doesn't explain the 40,000 kg reading ➜ you should really explore what the HX711 reads return.
I can't comment much on the hardware design, I'm not a pro there and if you took the layout from spark fun and did a correct soldering job, then I assume it's fine. Quality of the power supply does matter - may be something to check too.





