ESP32 Sampling digital 433mhz signal

marc1200
Posts: 1
Joined: Thu Nov 25, 2021 10:16 pm

ESP32 Sampling digital 433mhz signal

Postby marc1200 » Thu Nov 25, 2021 10:29 pm

Hello,
i would like to receive data from my 433 mhz weather station, the protocol does work correctly, but the way of sampling pulses doesn't work, The code is orginally written for arduino. below the code. the problem is that it does not pick up the signal and put it in the rawsignal variable. the signal coming from the 433mhz receiver is inverted.
  1. #define MIN_RAW_PULSES                    20                                    // =8 bits. Minimal number of bits*2 that need to have been received before we spend CPU time on decoding the signal.
  2. #define RAWSIGNAL_SAMPLE_RATE             30                                    // Sample width / resolution in uSec for raw RF pulses.
  3. #define MIN_PULSE_LENGTH                  40                                    // Pulses shorter than this value in uSec. will be seen as garbage and not taken as actual pulses.
  4. #define SIGNAL_TIMEOUT                     5                                    // Timeout, after this time in mSec. the RF signal will be considered to have stopped.
  5. #define SIGNAL_REPEAT_TIME               250                                    // Time in mSec. in which the same RF signal should not be accepted again. Filters out retransmits.
  6. #define BAUD                            9600                                    // Baudrate for serial communication.
  7.  
  8. #define RAW_BUFFER_SIZE                  256                                    // Maximum number of pulses that is received in one go.
  9.                      
  10. #define SCAN_HIGH_TIME                    50                                    // tijdsinterval in ms. voor achtergrondtaken snelle verwerking
  11. #define FOCUS_TIME                        50                                    // Duration in mSec. that, after receiving serial data from USB only the serial port is checked.
  12. #define PRINT_BUFFER_SIZE                 60                                   // Maximum number of characters that a command should print in one go via the print buffer.
  13.  
  14.  
  15. const unsigned long LoopsPerMilli=345;
  16. const unsigned long Overhead=0;  
  17.  
  18. int RawCodeLength=0;
  19. unsigned long PulseLength=0L;
  20. unsigned long numloops=0L;
  21. unsigned long maxloops=0L;
  22.  
  23. boolean Ftoggle=false;
  24. uint8_t Fbit=0;
  25. uint8_t Fport=0;
  26. uint8_t FstateMask=0;
  27.  
  28. #define WS1100_PULSECOUNT 94
  29. #define WS1200_PULSECOUNT 126
  30. #define ALECTOV3_PULSEMID 300/RAWSIGNAL_SAMPLE_RATE
  31.  
  32.  
  33.                                      
  34. #define PIN_RF_RX_DATA 15
  35.  
  36.  
  37. struct RawSignalStruct                                                          // Raw signal variabelen places in a struct
  38.   {
  39.   int  Number;                                                                  
  40.   byte Repeats;                                                              
  41.   byte Delay;                                                                  
  42.   byte Multiply;                                                              
  43.   unsigned long Time;                                                          
  44.   byte Pulses[RAW_BUFFER_SIZE+2];                                              
  45.                                                                                
  46. } RawSignal={0,0,0,0,0,0L};
  47.  
  48.  
  49. void FetchSignal() {
  50.  
  51.   DataPin = PIN_RF_RX_DATA;
  52.  
  53.  Fbit = !digitalPinToBitMask(DataPin);
  54.  Fport = digitalPinToPort(DataPin);
  55.  FstateMask = (StateSignal ? Fbit : 0);
  56.  
  57.   //Serial.println("Pass1");
  58.   unsigned long Timer=millis()+SCAN_HIGH_TIME;  
  59.   while(Timer>millis() || RepeatingTimer>millis()) {
  60.    //Fbit = !digitalRead(PIN_RF_RX_DATA);  
  61.  //Serial.println("Pass2");
  62.   if(Fbit == true){  
  63.  
  64.     //Serial.println("Pass3");
  65.     if (RawSignal.Time) {                                                      
  66.       if (RawSignal.Repeats && (RawSignal.Time+SIGNAL_REPEAT_TIME)>millis()) {
  67.         PulseLength=micros()+SIGNAL_TIMEOUT*1000;  
  68.         //Serial.println("Pass4");// delay
  69.         while ((RawSignal.Time+SIGNAL_REPEAT_TIME)>millis() && PulseLength>micros())
  70.           if ((*portInputRegister(Fport) & Fbit) == FstateMask)
  71.           //Serial.println("Pass5");
  72.             PulseLength=micros()+SIGNAL_TIMEOUT*1000;
  73.         while((RawSignal.Time+SIGNAL_REPEAT_TIME)>millis() &&  ((*portInputRegister(Fport) & Fbit) != FstateMask));
  74.       }
  75.     }
  76.     //Serial.println("Pass6");
  77.     RawCodeLength=1;                                                            // Start at 1 for legacy reasons. Element 0 can be used to pass special i    formation like plugin number etc.
  78.       Ftoggle=false;  
  79.        //Serial.println("Pass7");              
  80.     maxloops = (SIGNAL_TIMEOUT * LoopsPerMilli);  
  81.     do{      
  82.       //Serial.println("Pass8"); // read the pulses in microseconds and place them in temporay buffer RawSignal
  83.         numloops = 0;
  84.       while ((Fbit == true) ^ Ftoggle)      // while() loop *A*
  85.         if (numloops++ == maxloops) break;                        
  86.         //Serial.println("Pass9"); // timeout
  87.       PulseLength=((numloops + Overhead)* 1000) / LoopsPerMilli;                // Contains pulslength in microseconds
  88.       if (PulseLength<MIN_PULSE_LENGTH) break;                                  // Pulse length too short
  89.       Ftoggle=!Ftoggle;    
  90.       RawSignal.Pulses[RawCodeLength++]=PulseLength/(unsigned long)(RAWSIGNAL_SAMPLE_RATE); // store in RawSignal !!!!
  91.     }
  92.    
  93.     while (RawCodeLength<RAW_BUFFER_SIZE && numloops<=maxloops);  
  94.     //Serial.println("Pass10");              // For as long as there is space in the buffer, no timeout etc.
  95.     if (RawCodeLength>=MIN_RAW_PULSES) {
  96.       RawSignal.Repeats=0;                                                      // no repeats
  97.       RawSignal.Multiply=RAWSIGNAL_SAMPLE_RATE;                                 // sample size.
  98.       RawSignal.Number=RawCodeLength-1;                                         // Number of received pulse times (pulsen *2)
  99.       RawSignal.Pulses[RawSignal.Number+1]=0;                                   // Last element contains the timeout.
  100.       RawSignal.Time=millis();                                                  // Time the RF packet was received (to keep track of retransmits
  101.       Serial.println("Pass11");
  102.     }
  103.     else {
  104.       RawSignal.Number=0;  
  105.  //Serial.println("Pass12");
  106.        
  107.     }
  108.              
  109.      RepeatingTimer=millis()+SIGNAL_REPEAT_TIME;
  110.  
  111.    //Serial.println("Pass4");
  112.  
  113.   }
  114.   }
  115. }
  116.  
  117.  
  118.  

Who is online

Users browsing this forum: PepeTheGreat and 53 guests