Hi, I want to know how I can add an ethernet connection to the project named plant monitoring system.
Im using a CPU with an ethernet cable connected and I want to change my below code made with app Blynk to be suitable for ethernet
PLEASE HELP ASAP!!
As you didn’t post any code, it’s difficult to say. It’s also difficult to provide information when the only information about your hardware is…
Pete.
Heres the code,
// IOT Smart Plant Monitoring System
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
char auth[ ] =" "; //Authentication code sent by Blynk
char ssid[] = " "; //WiFi SSID
char pass[] = " "; //WiFi Password
#define sensorPin D3
int sensorState = 0;
int lastState = 0;
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V5, h); //V5 is for Humidity
Blynk.virtualWrite(V6, t); //V6 is for Temperature
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(sensorPin, INPUT);
dht.begin();
timer.setInterval(1000L, sendSensor);
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
sensors.begin();
}
int sensor=0;
void sendTemps()
{
sensor=analogRead(A0);
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
Serial.println(temp);
Serial.println(sensor);
Blynk.virtualWrite(V1, temp);
Blynk.virtualWrite(V2,sensor);
delay(1000);
}
void loop()
{
Blynk.run();
timer.run();
sendTemps();
sensorState = digitalRead(sensorPin);
Serial.println(sensorState);
if (sensorState == 1 && lastState == 0) {
Serial.println("needs water, send notification");
Blynk.notify("Water your plants");
lastState = 1;
delay(1000);
//send notification
}
else if (sensorState == 1 && lastState == 1) {
//do nothing, has not been watered yet
Serial.println("has not been watered yet");
delay(1000);
}
else {
//st
Serial.println("does not need water");
lastState = 0;
delay(1000);
}
delay(100);
}```
@HobbyHours Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Copy and paste these if you can’t find the correct symbol on your keyboard.
Pete.
1 Like
And are you going to share any information about your hardware?
This is a sketch for an ESP8266 using WiFi.
Are you using an ESP8266 based board, and if so what type of board is it, and what type of Ethernet adapter are you using, and how is it connected?
Pete.
yes, Nodemcu esp8266 board using Wifi and I just connected the ethernet cable to my mini pc in a port
my project uses DHT11 sensor, water pump using 9V, Relay and moisture sensor with LCD screen
You’re going to have to explain MUCH more about your hardware setup and what you’re trying to achieve if you want any meaningful help with this.
If you’re looking for an Ethernet connectivity solution you might be better going down this route…
I have a project where using a wired Ethernet connection, and providing power via the Ethernet cable (Power Over Ethernet) will be the neatest solution.
I bought one of these “LILYGO® TTGO T-Internet-POE ESP32-WROOM LAN8720A Chip Ethernet Adapter” boards to experiment with…
[image]
Although I won’t be running Blynk code on the board (I’ll be using my normal MQTT approach, with Node-Red acting as the bridge to Blynk) I thought I’d experiment a little first and get Blynk running on it.
There’s…
Pete.
1 Like