What I'm trying to do is replicate this alarm code I did using Arduino and a pair of nRF24L01 to a pair of ESP8266 ESP-07
===================================================================================================
Transmitter
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7; // Test Switch & W. Sensor
int ledPin = 2; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
int calibrationTime = 30; //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
long unsigned int lowIn; //the time when the sensor outputs a low impulse
long unsigned int pause = 5000; //the amount of milliseconds the sensor has to be low before we assume all motion has stopped
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 3; //the digital pin connected to the PIR sensor's output
int ledPIRPin = 8; // Led pin for PIR motion sensor
void setup(void){
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPIRPin, OUTPUT);
digitalWrite(pirPin, LOW);
Serial.print("calibrating sensor "); //give the sensor some time to calibrate
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
radio.begin();
radio.openWritingPipe(pipe);}
/*
* --------------------bigining of RF Radio---------------------------
*/
void loop(void){
if (digitalRead(SW1) == HIGH){
msg[0] = 111;
digitalWrite(ledPin, HIGH);
radio.write(msg, 1);}
if (digitalRead(SW1) == LOW){
digitalWrite(ledPin, LOW);}
/*
* --------------------End of RF Radio-----------------------------------
*/
/*
* --------------------bigining of PIR motion sensor---------------------
*/
if(digitalRead(pirPin) == HIGH){
msg[0] = 111;
radio.write(msg, 1);
digitalWrite(ledPIRPin, HIGH); //the led visualizes the sensors output pin state
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
digitalWrite(ledPIRPin, LOW); //the led visualizes the sensors output pin state
if(takeLowTime){
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
Serial.print("motion ended at "); //output
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}
=======================================================================================================
Receiver
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#define Buzzer 8 //Attach Buzzer to Arduino Digital Pin 8
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;
void setup(void){
pinMode(Buzzer, OUTPUT); //The Buzzer is an Output
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LED1, OUTPUT);}
void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);
delay(200);
noTone(Buzzer);
tone(Buzzer, 440, 200); // play a note on pin 6 for 200 ms:
delay(200);
noTone(Buzzer); // turn off tone function for pin 6:
tone(Buzzer, 494, 500); // play a note on pin 7 for 500 ms:
delay(500);
noTone(Buzzer); // turn off tone function for pin 7:
tone(Buzzer, 523, 300); // play a note on pin 8 for 500 ms:
}
else {digitalWrite(LED1, LOW);}
delay(10);}}
else{Serial.println("No radio available");}}
=================================================================================================
Can someone help me translate this to LUA
Thanks