0

Webserver to ESP8266 to UNO Issue
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Webserver to ESP8266 to UNO Issue

by scotch1 on Sun Aug 01, 2021 2:02 am

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 | TOGGLE FULL SIZE
/*********
  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 238 times

scotch1
 
Posts: 240
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

by adafruit_support_mike on Tue Aug 03, 2021 12:43 am

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.

adafruit_support_mike
 
Posts: 63728
Joined: Thu Feb 11, 2010 2:51 pm

Re: Webserver to ESP8266 to UNO Issue

by scotch1 on Fri Aug 20, 2021 1:31 am

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

scotch1
 
Posts: 240
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

by adafruit_support_mike on Fri Aug 20, 2021 2:17 pm

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

adafruit_support_mike
 
Posts: 63728
Joined: Thu Feb 11, 2010 2:51 pm

Re: Webserver to ESP8266 to UNO Issue

by scotch1 on Tue Sep 07, 2021 2:03 am

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?
:)

scotch1
 
Posts: 240
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

by adafruit_support_mike on Thu Sep 09, 2021 12:43 pm

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

adafruit_support_mike
 
Posts: 63728
Joined: Thu Feb 11, 2010 2:51 pm

Re: Webserver to ESP8266 to UNO Issue

by scotch1 on Thu Sep 09, 2021 6:59 pm

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

scotch1
 
Posts: 240
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

by scotch1 on Thu Sep 09, 2021 7:03 pm

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..

scotch1
 
Posts: 240
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

by scotch1 on Mon Sep 13, 2021 2:26 am

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?

scotch1
 
Posts: 240
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

by adafruit_support_mike on Tue Sep 14, 2021 5:53 pm

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.

adafruit_support_mike
 
Posts: 63728
Joined: Thu Feb 11, 2010 2:51 pm

Re: Webserver to ESP8266 to UNO Issue

by scotch1 on Wed Sep 15, 2021 10:19 pm

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.

scotch1
 
Posts: 240
Joined: Mon Nov 26, 2012 12:13 am

Re: Webserver to ESP8266 to UNO Issue

by adafruit_support_mike on Sun Sep 19, 2021 9:53 pm

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.

adafruit_support_mike
 
Posts: 63728
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.