Arduino - NodeMCU with Arduino IOT Cloud

Hello,

I have to say that i'm begginer on Arduino, i like it, and now i want to make a little project.

I get a Marker Plan on Arduino IOT Cloud, i have a NodeMCU board and i want to control a relay with, i run a simple cod, without IOT Cloud and it works.

My problems is, that i don't know how to handle that sketch:

/*
Sketch generated by the Arduino IoT Cloud Thing "NodeMCU-Test"
https://create.arduino.cc/cloud/things/e14af433-7349-49c1-9f27-7c7c29f4aa29

Arduino IoT Cloud Properties description

The following variables are automatically generated and updated when changes are made to the Thing properties

bool pornirePompa;
bool pornireVentilatie;
float temperatura;

Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#define relay 5

void setup() {
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);

// Defined in thingProperties.h
initProperties();

// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);

/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}

void loop() {
ArduinoCloud.update();
// Your code here

}

void onPornirePompaChange() {
Don't know what to put here
}
}

void onTemperaturaChange() {
// Do something
}

void onPornireVentilatieChange() {
// Do something
}

void onFfsdfChange() {
// Do something
}

Thanks,

Alex

Hi Alexk-Alexandru

The sketch that you show looks like an 'off the shelve - fits all' IOT skeleton sketch that seems to work in conjunction with Arduino IoT Cloud. This is an IOT sketch that most probably won't function at local level. You say that you want to do a local action. Why then a IOT script?

Please throw away the script you quote and begin fresh:

  1. define exactly what you want your NodMCU to do
  2. define the sensors
  3. define the actuators, or the output device
  4. work out the decisions based on sensor data and the effect of these decisions on the actuators

Success

Hello,

I don't want to run a local sketch, i just say that i use a sketch to test nodemcu + relay on local, now i want to put that on Arduino IoT Cloud but i don't know how to make that sketch. i know how to wire, i know how to use dashboard and property. i made a button and link on that
void onPumpChange() {
}
but i don't know what i have to put on that, i try with digitalWrite(relay, HIGH); but when board start, relay get on, my dashboard button don't work, that because i have wrong code on sketch.

Hi aleck-alexandru,

I really do not grasp what you are planning. Sorry . . . . :o

Can you please inform us what you exactly want - show a picture of your project, maybe some lines of code - the IOT sketch is just an empty shell with no real meaning!

regards, photoncatcher

Hello,

I have a NodeMCU board with 1 relay module. I want to use that Arduino IOT Cloud to control that relay. But i don't know how do to that.

I need some help with a code, if someone use that before. I don't know where to start.

Hello,

Ok, found it :slight_smile:

void onPumpChange() {
int relayState = digitalRead(relay);
if (relayState == 0)
{
digitalWrite(relay, HIGH);
} else {
digitalWrite(relay, LOW);
}
}