2. Getting Started with NodeMCU

2.1. Download and install Arduino NodeWire library

Install the NodeWire Arduino library

  1. Download the library from here.
  2. Launch the Arduino IDE
  3. On the Sketch menu select ‘Include Library’ then ‘Add .ZIP Library...’
_images/addlibrary.png
  1. Browse and select the zip file you downloaded in step 1
  2. Check the File - Examples menu to see the library is correctly installed
_images/arduinolib.png

2.2. Create Arduino node

  1. Create a new Arduino sketch by selecting the ‘Uno Board’ NodeWire sample in the Examples menu. This sample converts the Arduino Uno board into a NodeWire node with 18 ports.
  2. Connect your Arduino board to your computer’s usb port and then upload the sketch to your board.
  3. Start the NodeWire gateway. If it is already running, you should terminate and start it again. You may have to wait a few minutes before restarting.

2.3. Use the NodeWire Dashboard to control the node

Log-in to the NodeWire Dashboard. using the same account you used to configure the gateway. Wait for about 10 seconds for the auto-layout to load.

#include <nnode.h>
#include <nesp8266link.h>

#define LED LED_BUILTIN

Node<int> node;
Esp8266Link link;

void setup() {
  Serial.begin(38400);
  debug.setOutput(&Serial);
  debug.level = LOW_LEVEL;

  link.begin();

  node.inputs = "led";
  node.init("node01");
  node.setLink(&link);

  node.on("led",
     [](nString val, nString sender) {
        digitalWrite(LED,(int)val);
     }
  );

  pinMode(LED, OUTPUT);
}

void loop() {
  node.run();
}