Go Down

Topic: Wifi Sensor HTML not working (Read 51 times) previous topic - next topic


Hi all
I am working on a project where i am making sensors transmit to a very basic html page. I can upload the code, so i don't have any arduino coding errors, but the html page just does not work. I mostly get the


error, and it should be showing my sensor data.

I am using an arduino uno wifi rev2.

Any thoughts  on what i can do or how to help?

P.S. i have blanked out my network username and password for privacy reasons
excuse all my //notes - it's documentation as its a school project :)

Code: [Select]
#define DHTPIN 11          // Which pin my DHT (temp + humidity sensor) is connected to
#include "DHT.h"           // Including the Library allowing you to use a DHT
#define DHTTYPE DHT22      // What type of DHT I own
#include <SPI.h>           // The library for communicating with other devices- I spent weeks trying to find out
                           // why my code wouldn't work and this was the answer
#include <WiFiNINA.h>      // Including the Library allowing me to connect to WiFi

int soilPin = A0;          // The Analog pin my soil sensor is connected to
int tempPin = 11;          // The Digital pin my temperature and humidity temperature is connected to
int lightPin = A2;         // The Analog pin my photoresistor is connected to

char ssid[] = "-------";     // Network SSID (name)
char pass[] = "-------";    // Network password
// int keyIndex = 0;             // Network key Index number (needed only for WEP)

WiFiServer server(80);           // Declare server object and specify port, 80 is port used for internet
int status = WL_IDLE_STATUS;     // Status of wifi

DHT dht(DHTPIN, DHTTYPE);        // Small bit of code allowing my DHT to read information
                                 // I spent weeks trying to find why it wouldn't work, before adding this

void setup() {                // Complete this code upon setup and never again
  Serial.begin(9600);         // Start the Serial Monitor, allowing me to print sensor data
  dht.begin();                // Begin my DHT sensor
  pinMode(soilPin, INPUT);        // Set soilPin as an Input (to recieve data)
  pinMode(tempPin, INPUT);        // Set tempPin as an Input (to recieve data)
  while ( status != WL_CONNECTED) {        // Attempt to connect to Wifi network
    status = WiFi.begin(ssid, pass);       // Connect to WPA/WPA2 network. Change this line if using open or WEP network
    delay(10000);                          // Delay 10 seconds (allow for connection)
  server.begin();             // Begin the WiFi

void loop() {            // Start
  WiFiClient client = server.available();   // listen for incoming clients
  if (client) {                             // if you get a client,
  String currentLine = "";                // make a String to hold incoming data from the client
   while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
          Serial.write(c);                    // print it out the serial monitor
               if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            float h = dht.readHumidity();
            float t = dht.readTemperature();

            client.print("Humidity: ");
            client.println(" %\t");
            client.print("Temperature: ");
            client.println(" *C ");
            client.print("  Soil Moisture: ");   
            client.print("Light Value:  ");

            // The HTTP response ends with another blank line:
            // break out of the while loop:
          else {      // if you got a newline, then clear currentLine:
            currentLine = "";
        else if (c != '\r') {    // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
}      }


Normally (assuming this is an ESP8266 device) the server is handled differently.

client is a client; so for outgoing connections.

You usually have one or more server.on("/", handleRoot); lines where you define the available services, and then you call server.handleClient() in the loop() to check for incoming connections.

See also this example.

Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up