fabrizio97726

Lora sender 433

Jul 27th, 2025 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.81 KB | None | 0 0
  1. esphome:
  2.   name: lora-1
  3.   friendly_name: lora-1
  4.  
  5. esp32:
  6.   board: esp32dev
  7.   framework:
  8.     type: arduino
  9.  
  10.  
  11.  
  12.  
  13. # Enable logging
  14. logger:
  15.   level: VERY_VERBOSE  
  16.  
  17. # Enable Home Assistant API
  18. api:
  19.   encryption:
  20.     key: ""
  21.  
  22. ota:
  23.   - platform: esphome
  24.     password: ""
  25.   - platform: web_server
  26.  
  27. wifi:
  28.   ssid: !secret wifi_ssid
  29.   password: !secret wifi_password
  30.   use_address: 192.168.68.75
  31.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  32.   ap:
  33.     ssid: ""
  34.     password: ""
  35.  
  36.  
  37.  
  38. web_server:
  39.   port: 80
  40.   version: 3
  41.   include_internal: true
  42.   local: true
  43.  
  44. spi:
  45.   clk_pin: GPIO5
  46.   mosi_pin: GPIO27
  47.   miso_pin: GPIO19  
  48.  
  49. # CONFIGURAZIONE LORA COMPONENTE SX 1276
  50. sx127x:
  51.   dio0_pin: GPIO26
  52.   cs_pin: GPIO18
  53.   rst_pin: GPIO23 # verificare versione scheda
  54.   pa_pin: BOOST
  55.   pa_power: 17
  56.   bandwidth: 125_0kHz
  57.   crc_enable: true
  58.   frequency: 433920000
  59.   modulation: LORA
  60.   rx_start: true
  61.   sync_value: 0x12
  62.   spreading_factor: 7
  63.   coding_rate: CR_4_5
  64.   preamble_size: 6  
  65.   on_packet:
  66.     then:
  67.       - lambda: |-
  68.           ESP_LOGD("lambda", "packet %s", format_hex(x).c_str());
  69.           ESP_LOGD("lambda", "rssi %.2f", rssi);
  70.           ESP_LOGD("lambda", "snr %.2f", snr);    
  71.           id(last_rssi) = rssi;
  72.           id(lora_packet_count) += 1;
  73.           ESP_LOGI("lora", "Pacchetto ricevuto. Totale: %d", id(lora_packet_count));
  74.           id(lora_sent_count) += 1;
  75.           ESP_LOGI("lora", "Pacchetto inviato. Totale: %d", id(lora_sent_count));
  76.  
  77. globals:
  78.   - id: last_rssi
  79.     type: float
  80.     restore_value: no
  81.     initial_value: '0.0'
  82.  
  83.   - id: lora_packet_count
  84.     type: int
  85.     restore_value: no  # se vuoi mantenere il conteggio dopo il riavvio
  86.     initial_value: '0'
  87.  
  88.   - id: lora_sent_count
  89.     type: int
  90.     restore_value: no  # mantiene il conteggio al riavvio
  91.     initial_value: '0'    
  92.  
  93.  
  94.  
  95. packet_transport:
  96.   platform: sx127x
  97.   update_interval: 1s
  98.   encryption: "fabrizio"
  99.   binary_sensors:
  100.    - rele_lora1
  101.   providers:
  102.     - name: lora-2
  103.       encryption: "fabrizio"
  104.  
  105. sensor:
  106. #WIFI
  107.   - platform: wifi_signal
  108.     name: "WiFi Signal lora 1"
  109.     update_interval: 15s
  110.     filters:
  111.       - sliding_window_moving_average:
  112.           window_size: 15
  113.           send_every: 15
  114.           send_first_at: 15
  115.     icon: mdi:wifi  
  116.  
  117.   - platform: template
  118.     name: "LoRa RSSI"
  119.     unit_of_measurement: "dBm"
  120.     accuracy_decimals: 1
  121.     update_interval: 5s
  122.     lambda: |-
  123.       return id(last_rssi);    
  124.  
  125.   - platform: template
  126.     name: "LoRa Pacchetti Ricevuti"
  127.     lambda: |-
  128.       return id(lora_packet_count);
  129.     update_interval: 5s
  130.     unit_of_measurement: "pkt"
  131.     accuracy_decimals: 0      
  132.  
  133.   - platform: template
  134.     name: "LoRa Pacchetti Inviati"
  135.     lambda: |-
  136.       return id(lora_sent_count);
  137.     update_interval: 10s
  138.     unit_of_measurement: "pkt"
  139.     accuracy_decimals: 0                
  140.    
  141. button:
  142.   - platform: template
  143.     name: "Transmit Packet"
  144.     on_press:
  145.       then:
  146.         - sx127x.send_packet:
  147.             data: [0xC5, 0x51, 0x78, 0x82, 0xB7, 0xF9, 0x9C, 0x5C]
  148.  
  149.   - platform: template
  150.     name: "Apri cancello box"
  151.     id: apri_cancello_box
  152.     icon: "mdi:gate"
  153.     on_press:                      
  154.       - switch.turn_on: rele  
  155.       - delay: 3s                
  156.       - switch.turn_off: rele      
  157.  
  158.  
  159.   - platform: restart
  160.     name: "Restart"  
  161.                
  162. switch:
  163.   - platform: template
  164.     name: Relè
  165.     id: rele
  166.     optimistic: True
  167.    
  168.  
  169. binary_sensor:
  170.   - platform: template
  171.     id: rele_lora1
  172.     lambda: return id(rele).state;
  173.  
  174.   - platform: packet_transport
  175.     id: rele_lora2
  176.     provider: lora-2
  177.     on_press:
  178.       switch.turn_on: rele
  179.  
  180.     on_release:
  181.       then:
  182.         - delay: 2s                
  183.         - switch.turn_off: rele  
  184.  
Advertisement
Add Comment
Please, Sign In to add comment