Webserver to ESP8266 to UNO Issue

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
scotch1
 
Posts: 246
Joined: Mon Nov 26, 2012 12:13 am

Webserver to ESP8266 to UNO Issue

Post by scotch1 »

Trying to use a website html slider to change values which are read by an ESP8266 (or feather huzzah) remotely (on wifi network) and successfully can dim an LED.
Seeking to have UNO read the values to the serial but they don't make any sense.
Values are 0-1023 from website slider.
Tried outputting to esp8266 D1, D5, and A0 (analog), all control LED, but no values to UNO.
Is there a communication issue and or should there be more than one wire connecting the ESP2866 D1 (or A0) to A0 on the UNO? SHould it go to digital 1 on the UNO for RX?
Any input appreciated:
Full code:

Code: Select all

/*********
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp8266-nodemcu-web-server-slider-pwm/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*********/

// Import required libraries
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>

// Replace with your network credentials
const char* ssid = "x";
const char* password = "y";

const int output = D5;

String sliderValue = "0";

const char* PARAM_INPUT = "value";

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Test SIte</title>
  <style>
    html {font-family: Arial; display: inline-block; text-align: center;}
    h2 {font-size: 2.3rem;}
    p {font-size: 1.9rem;}
    body {max-width: 400px; margin:0px auto; padding-bottom: 25px;}
    .slider { -webkit-appearance: none; margin: 14px; width: 360px; height: 25px; background: #FFD65C;
      outline: none; -webkit-transition: .2s; transition: opacity .2s;}
    .slider::-webkit-slider-thumb {-webkit-appearance: none; appearance: none; width: 35px; height: 35px; background: #003249; cursor: pointer;}
    .slider::-moz-range-thumb { width: 35px; height: 35px; background: #003249; cursor: pointer; } 
  </style>
</head>
<body>
  <h2>Test SLider</h2>
  <p><span id="textSliderValue">%SLIDERVALUE%</span></p>
  <p><input type="range" onchange="updateSliderPWM(this)" id="pwmSlider" min="0" max="1023" value="%SLIDERVALUE%" step="1" class="slider"></p>
<script>
function updateSliderPWM(element) {
  var sliderValue = document.getElementById("pwmSlider").value;
  document.getElementById("textSliderValue").innerHTML = sliderValue;
  console.log(sliderValue);
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value="+sliderValue, true);
  xhr.send();
}
</script>
</body>
</html>
)rawliteral";

// Replaces placeholder with button section in your web page
String processor(const String& var){
  //Serial.println(var);
  if (var == "SLIDERVALUE"){
    return sliderValue;
  }
  return String();
}

void setup(){
  // Serial port for debugging purposes
  Serial.begin(115200);

  analogWrite(output, sliderValue.toInt());

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }

  // Print ESP Local IP Address
  Serial.println(WiFi.localIP());

  // Route for root / web page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html, processor);
  });

  // Send a GET request to <ESP_IP>/slider?value=<inputMessage>
  server.on("/slider", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    // GET input1 value on <ESP_IP>/slider?value=<inputMessage>
    if (request->hasParam(PARAM_INPUT)) {
      inputMessage = request->getParam(PARAM_INPUT)->value();
      sliderValue = inputMessage;
      analogWrite(output, sliderValue.toInt());
    }
    else {
      inputMessage = "No message sent";
    }
    Serial.println(inputMessage);
    request->send(200, "text/plain", "OK");
  });
  
  // Start server
  server.begin();
}
  
void loop() {
  
}
91.JPG
91.JPG (113.75 KiB) Viewed 741 times

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Webserver to ESP8266 to UNO Issue

Post by adafruit_support_mike »

The ESP8266 doesn’t have any analog output. It has one analog input that can read values between 0V and 1V, but that’s all.

It would make more sense for the ESP8266 to send information about the slider through a Serial connection.

User avatar
scotch1
 
Posts: 246
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

Post by scotch1 »

Would you happen to have or know of guidance for that effort?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Webserver to ESP8266 to UNO Issue

Post by adafruit_support_mike »

If the ESP8266 is connected to the Arduino IDE’s Serial Monitor, just sending the value through Serial.print() should be fine.

User avatar
scotch1
 
Posts: 246
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

Post by scotch1 »

Uploaded the latest FIrmata for BLE control of nRF52832.
Control of Analog 1 using slider worked to light up an LED (Great).
Attempt to connect Bluefruit to Arduino UNO with AnalogReadSerial on A0 was "spikey" and inconsistent.
Tried smoothing and changing delay but not consistent values.
So, tried thru Arduino digital 0, (RX), same as before, inconsistent.
Then connected to A0 thru a resistor (same circuit as an LED, except the Arduino A0 with resistor) wasn't sure I damaged it ;(

Is there a buffering issue?
WHat is the easiest way to take the BLE values and let arduino reliably read in either a pin or serial?
:)

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Webserver to ESP8266 to UNO Issue

Post by adafruit_support_mike »

I’m not sure what you mean by “spiky” and “inconsistent”. Could you post a sequence of actual readings please?

User avatar
scotch1
 
Posts: 246
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

Post by scotch1 »

FOr example:

Wire from A0 on nRF8 to A0 of UNO, then Analog Read on UNO, open serial port.

If the SLider on IPhone for BLE (Pin I/O, Pin 3, Analo 1, PWM) was 0, serial would read increasing and decreasing number from 0 to 1023 ish on a 10ms delay,

If the SLider on IPhone for BLE was 255, serial would read the same increasing and decreasing values, like it was changing on it's own from one end up to the other end of the 1024 range.

It appears to cycle up and down, independent of the slider control.

All I am trying to do is have the BLE send a slider value the arduino can use like a POT.

(example output from Serial:)
8
8
11
11
11
9
19
42
101
194
295
381
471
561
659
761
852
930
964
973
974
984
985
997
1002
1002
1002
1002
1011
1011
1011
1013
1019
1019
997
944
858
756
678
592
497
399
296
194
114
65
49
50

User avatar
scotch1
 
Posts: 246
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

Post by scotch1 »

Is there anyway I can pay for support to
1)
create a simple webserver (socket) with a slider on it that communicates with the ESP or Bluefruit on BLE in realtime to post the values on an local IP like 168.192.0.1/values and they update in realtime?
2) use the BLE slider to do the same: so the BLE PWM values send a value to an IP that my laptop can connect onto and see the values in the browser changing?
I think I have all the parts (I.e the webinterface), might need hardware connectivity and realtime updating..

User avatar
scotch1
 
Posts: 246
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

Post by scotch1 »

Have the ESP8266 working for a local ip webserver.
WOuld like to be able to have the bluefruit send usable data to a webserver page, but having the firmata on the nFR... is throwing me off: How to generate the webpage and control thru BLE? Is that even possible?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Webserver to ESP8266 to UNO Issue

Post by adafruit_support_mike »

The ESP8266 can't do BLE. You'd have to use another device that can operate as a BLE central device, like the nRF52832 or nRF52840:

https://www.adafruit.com/product/3406
https://www.adafruit.com/product/4062

and have that share information with the ESP8266.

User avatar
scotch1
 
Posts: 246
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

Post by scotch1 »

Have the nRF52832 : can do BLE but can't seem to get the values to be read by Arduino pins. ALso, can't seem to send BLE firmata AND a webserver to the nRF52832 . Seems it's one or the other.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Webserver to ESP8266 to UNO Issue

Post by adafruit_support_mike »

The nRF83532 doesn't do Wifi, so no, you won't be able to run a webserver from that.

You need to run the webserver on the ESP8266, a BLE central device on the nRF83532, then pass information between them with something like a Serial connection.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”