muddypawprintz
muddypawprintz

Reputation: 1

Lua ESP8266 script expecting extra =

I am trying to test a proximity sensor with my ESP8266, however the test code I am using keeps failing. Whenever I run the code, I get an error: motion sensor.lua:1: '=' expected near 'int'

I should also mention I am using ESPlorer v0.2.0

const int PIRSensorOutPin = 2;    //PIR Sensor OUT Pin
void setup() {
   Serial.begin(9600);
  pinMode(PIRSensorOutPin, INPUT);
}
void loop()
{
    if (digitalRead(PIRSensorOutPin) == LOW)
    {
       Serial.println("Person detected!");    //Print to serial monitor
    }
    else {;}
 }

What am I doing wrong?

Upvotes: -1

Views: 113

Answers (2)

DarkWiiPlayer
DarkWiiPlayer

Reputation: 7056

What am I doing wrong?

Using the wrong programming language.

NodeMCU wants to run Lua code and you're giving it C code instead, which just can't work.

How do I fix it? (implied)

You can use the arduino IDE to write C++ code for ESP8266, but since you already seem to have everything set up to run Lua code, I suggest just using that instead.

The C code you provided could be rewritten into Lua using the NodeMCU api like this:

local pin = 2 -- The number of the I/O Pin
local type = "down" -- Trigger on falling edge

-- https://nodemcu.readthedocs.io/en/master/modules/gpio/#gpiotrig
gpio.trig(pin, type, function()
   print("Movement detected, proceding to exterminate!")
end)

Upvotes: 0

Piglet
Piglet

Reputation: 28950

The Lua interpreter doesn't understand C++.

You're running NodeMCU firmware which runs Lua files. But you're trying to run Arduino C++ code. That's not going to work. To run this code you would have to add ESP8266 support to your Arduino IDE, compile your code and flash it onto the ESP.

Alternatively write your code in Lua.

https://github.com/esp8266/Arduino

https://www.nodemcu.com/index_en.html

Upvotes: 0

Related Questions