Hirdetés

Új hozzászólás Aktív témák

  • olli

    tag

    ```cpp
    #include <SPI.h>
    #include <LoRa.h>
    int state;
    //LoRa32u4 ports
    #define SS 8
    #define RST 4
    #define DI0 7
    #define BAND 433E6
    void setup() {
    Serial.begin(115200);

    pinMode(13, OUTPUT); // fehér led sets the pin as output for relay
    digitalWrite(13,HIGH);
    //while (!Serial); //if just the the basic function, must connect to a computer
    delay(1000);

    SPI.begin();
    LoRa.setPins(SS,RST,DI0);
    Serial.println("LoRa Receiver");

    if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
    }
    Serial.println("LoRa Initial OK!");
    }
    /*----( LOOP: RUNS CONSTANTLY )----*/
    void loop() {
    digitalWrite(13,LOW);
    // try to parse packet
    int packetSize = LoRa.parsePacket();
    if (packetSize) {
    // received a packet
    Serial.print("Received packet :");
    // read packet
    while (LoRa.available()) {
    Serial.print((char)LoRa.read());
    }
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
    while (LoRa.available()) {
    Serial.println();
    state = ((char)LoRa.read());

    }

    if (state == 1) //If this code received then turn on pump
    {
    Serial.println("Pump ON");
    digitalWrite(13,LOW); //Pump relay ON
    delay(500);
    }
    if (state == 0) //If this code received then turn off pump
    {
    Serial.println("Tank Full - Pump OFF");
    digitalWrite(13,HIGH); //Pump relay OFF
    delay(3000);
    }
    }

    }

    serial print:```
    Received packet :hello 16.2515.25112121' with RSSI -78 Tank Full - Pump OFF
    Küldő oldalon mit is kellene megadnom, hogy kiváltsa a relé on-off kapcsolását?

Új hozzászólás Aktív témák