Webserver on ESP32 Sparkfun Thing

Hey good peoples,

I am very new to this but I bought an ESP32 Sparkfun Thing and an IMAX 31856 temperature sensor with a 3.2"TFT display.
I have managed to hook up the temp sensor and have it display the reading on the TFT OK using SPI.
I now want to host a webserver and use AJAX protocol to have my mobile phone display the temperature by typing IP address in a web browser on the phone. I stated looking into this and now have doubts as to whether the Sparkfun Thing can actually do this with a temperature reading and not just a digital signal. I may need the Sparkfun Thing Plus.
Im hoping im wrong but can someone confirm whether this is the case or not and if Im good to go point me to a good tutorial regarding coding for this?

This one may help:

I don't see why it wouldn't work. What feature gives you doubts?
Good tutorials for Esp32:

Cheers for the responses. I was able to get it working by using that tutorial and chopping bits out of the code and changing some values around.
Much appreciated.

If anyone is interested this is my working code.

#include <Adafruit_MAX31856.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Fonts/FreeMono12pt7b.h>
#include "WiFi.h"
#include "ESPAsyncWebServer.h"


// use hardware SPI, just pass in the CS pin
Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(5);

// Define adafruit TFT SPI wiring
#define TFT_CLK 13
#define TFT_CS 14
#define TFT_DC 27
#define TFT_MOSI 12

// Map SPI pins
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK);

// Replace with your network credentials
const char* ssid = "Bamghan";
const char* password = "Jaryki83";

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

// Convert MAX31856 readings to String
String readDHTTemperature() {
  // Read temperature as Celsius (the default)
  int t = maxthermo.readThermocoupleTemperature();
  // Check if any reads failed and exit early (to try again).
  if (isnan(t)) {    
    Serial.println("Failed to read from Max31856 sensor!");
    return "--";
  }
  else {
    // Serial.println(t);
    return String(t);
  }
}

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
  <style>
    html {
     font-family: Arial;
     display: inline-block;
     margin: 0px auto;
     text-align: center;
    }
    h2 { font-size: 3.0rem; }
    p { font-size: 3.0rem; }
    .units { font-size: 1.2rem; }
    .dht-labels{
      font-size: 1.5rem;
      vertical-align:middle;
      padding-bottom: 15px;
    }
  </style>
</head>
<body>
  <h2>Hayley's Kiln</h2>
  <p>
    <i class="fas fa-thermometer-half" style="color:#059e8a;"></i> 
    <span class="dht-labels">Temperature</span> 
    <span id="temperature">%TEMPERATURE%</span>
    <sup class="units">&deg;C</sup>
  </p>
</body>
<script>
setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("temperature").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "/temperature", true);
  xhttp.send();
}, 10000 ) ;
</script>
</html>)rawliteral";

// Replaces placeholder with DHT values
String processor(const String& var){
  //Serial.println(var);
  if(var == "TEMPERATURE"){
    return readDHTTemperature();
  }
  else return String();
}





// Start serial communications
void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);
  // Serial.println("MAX31856 thermocouple test");
  // Serial.println("ILI9341 Test!"); 

 // Begin maxthermo
  maxthermo.begin();

  // Begin TFT
  tft.begin();

  maxthermo.setThermocoupleType(MAX31856_TCTYPE_K);

  Serial.print("Thermocouple type: ");
  switch (maxthermo.getThermocoupleType() ) {
    case MAX31856_TCTYPE_B: Serial.println("B Type"); break;
    case MAX31856_TCTYPE_E: Serial.println("E Type"); break;
    case MAX31856_TCTYPE_J: Serial.println("J Type"); break;
    case MAX31856_TCTYPE_K: Serial.println("K Type"); break;
    case MAX31856_TCTYPE_N: Serial.println("N Type"); break;
    case MAX31856_TCTYPE_R: Serial.println("R Type"); break;
    case MAX31856_TCTYPE_S: Serial.println("S Type"); break;
    case MAX31856_TCTYPE_T: Serial.println("T Type"); break;
    case MAX31856_VMODE_G8: Serial.println("Voltage x8 Gain mode"); break;
    case MAX31856_VMODE_G32: Serial.println("Voltage x8 Gain mode"); break;
    default: Serial.println("Unknown"); break;
  }

  


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

  // Print ESP32 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);
  });
  server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", readDHTTemperature().c_str());
  });

  // Start server
  server.begin();
}




void loop() {
  //Serial.print("Cold Junction Temp: ");
  //Serial.println(maxthermo.readCJTemperature());

  Serial.print("Thermocouple Temp: ");
  Serial.println(maxthermo.readThermocoupleTemperature());
  // Check and print any faults
  uint8_t fault = maxthermo.readFault();
  if (fault) {
    if (fault & MAX31856_FAULT_CJRANGE) Serial.println("Cold Junction Range Fault");
    if (fault & MAX31856_FAULT_TCRANGE) Serial.println("Thermocouple Range Fault");
    if (fault & MAX31856_FAULT_CJHIGH)  Serial.println("Cold Junction High Fault");
    if (fault & MAX31856_FAULT_CJLOW)   Serial.println("Cold Junction Low Fault");
    if (fault & MAX31856_FAULT_TCHIGH)  Serial.println("Thermocouple High Fault");
    if (fault & MAX31856_FAULT_TCLOW)   Serial.println("Thermocouple Low Fault");
    if (fault & MAX31856_FAULT_OVUV)    Serial.println("Over/Under Voltage Fault");
    if (fault & MAX31856_FAULT_OPEN)    Serial.println("Thermocouple Open Fault");
  }

  // Convert floating point to integer for whole number readout on TFT.
  int thermointeger = (maxthermo.readThermocoupleTemperature());
  
  // TFT Display settings
  tft.setRotation(3);
  tft.fillScreen(ILI9341_BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.println();
  tft.setTextColor(ILI9341_WHITE);
  tft.setCursor(15, 140);
  tft.setFont(&FreeMono12pt7b);
  tft.setTextSize(5.9);
  tft.println(thermointeger);
  delay(10000);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.