-1

I am using Arduino 1.6.13 (Windows) to write and send sketches to NodeMCU. I have a custom NodeMCU built against the master branch. It includes file, gpio, http, mdns, mqtt, net, node, tmr, uart, websocket, wifi - using nodemcu-build.com. It was flashed without problem using esptool.py.

I have a simple sketch, which reacts on button press with a flashing led and runs a small PHP script on server side).

#include <ESP8266WiFi.h>
const char* ssid = "blahblahblah";
const char* password = "blahblahblahblah"; 
const int ledPin = D7;
const int buttonPin = D2;

void setup() {
    pinMode(ledPin, OUTPUT);
    pinMode(buttonPin, INPUT_PULLUP);
    Serial.begin(115200);
    delay(10);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
    }
}

void loop() {
    if (digitalRead(buttonPin) == LOW) {
        digitalWrite(ledPin, HIGH);
        delay(1000); 
        http.get("http://192.168.1.128/");
        digitalWrite(ledPin, LOW);
    }
}

Result of verification is:

In function 'void loop()': button_check_yapp:24: error: 'http' was not declared in this scope http.get("http://192.168.1.128/"); ^ exit status 1 'http' was not declared in this scope

What's wrong? What I did miss?

Thank you.

dda
  • 6,030
  • 2
  • 25
  • 34
Rafie
  • 9
  • 1
  • 3

2 Answers2

1

You either program in the Arduino IDE using Arduino code (as you have above) OR your program against the NodeMCU firmware using Lua code but not both. It's either or.

For NodeMCU you'd use something like ESPlorer to upload the Lua code. This allows for really fast prototyping as you only need to flash the firmware once. With Arduino you compile your own code with the chip maker SDK into a new binary every time you change your code.

Disclaimer: I'm biased as I'm one of the current NodeMCU firmware maintainers.

Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
0

The compiler gets an error, because it doesn't know the http function or variable. You either have to create the http variable or you need a other variable that knows the http function.

kakabali
  • 3,824
  • 2
  • 29
  • 58
Qcolon
  • 49
  • 5
  • While your post may solve the question, including an explanation along with code snippet really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the exact code where it faces error. – Pirate X Mar 28 '18 at 07:11