Published © Apache-2.0

Send Data From ESP to the Webpage with Minimal Efforts

A 10-minute tutorial on how to display data from ESP onto the webpage - also works with mobile phones.

BeginnerProtip30 minutes3,743
Send Data From ESP to the Webpage with Minimal Efforts

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Wemos D1 Mini
Espressif Wemos D1 Mini
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

RemoteMe.org cloud
RemoteMe.org cloud

Story

Read more

Schematics

Schematic

Code

Code snippet #1

Plain text
#define WIFI_NAME "ania24"
#define WIFI_PASSWORD "xxxxxx"
#define DEVICE_ID 11
#define DEVICE_NAME "esp"
#define TOKEN "~155_D49LDj@aBFhdffK."
 
 
#include <RemoteMe.h>
#include <RemoteMeSocketConnector.h>
#include <ESP8266WiFi.h>
 
#define TRIGGER D3
#define ECHO    D2
 
RemoteMe& remoteMe = RemoteMe::getInstance(TOKEN, DEVICE_ID);
 
//*************** CODE FOR CONFORTABLE VARIABLE SET *********************
 
inline void setDistance(int32_t i) {remoteMe.getVariables()->setInteger("distance", i); }
 
//*************** IMPLEMENT FUNCTIONS BELOW *********************
 
 
 
 
 
 
void setup() {
 
    WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
 
    while (WiFi.status() != WL_CONNECTED) {
        delay(100);
    }
    
    remoteMe.setConnector(new RemoteMeSocketConnector());
    remoteMe.sendRegisterDeviceMessage(DEVICE_NAME);
    pinMode(TRIGGER, OUTPUT);
    pinMode(ECHO, INPUT);
}
 
 
void loop() {
    remoteMe.loop();
    static long time=millis();
    if (time+700<millis()){//cannot send more frwquent since it will be block
      time=millis();
      setDistance(getDistance());
    }
 
}
 
int32_t getDistance(){
  digitalWrite(TRIGGER, LOW);  
  delayMicroseconds(2); 
  
  digitalWrite(TRIGGER, HIGH);
  delayMicroseconds(10); 
  
  digitalWrite(TRIGGER, LOW);
  long duration = pulseIn(ECHO, HIGH);
  return (duration/2) / 29.09;
  
  
}

Code snippet #4

Plain text
 static long time=millis();
    if (time+700<millis()){//cannot send more frwquent since it will be block
      time=millis();
      setDistance(getDistance());
    }

Code snippet #5

Plain text
int32_t getDistance(){
  digitalWrite(TRIGGER, LOW);  
  delayMicroseconds(2); 
  
  digitalWrite(TRIGGER, HIGH);
  delayMicroseconds(10); 
  
  digitalWrite(TRIGGER, LOW);
  long duration = pulseIn(ECHO, HIGH);
  return (duration/2) / 29.09;
}

Credits

Comments