Új hozzászólás Aktív témák

  • junhum

    tag

    Sziasztok!

    Volna egy kopizott kódom:
    #include <ESP8266WiFi.h>
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>
    #include <ESP8266mDNS.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>

    //pro teploměr
    #define ONE_WIRE_BUS D4
    #define TEMPERATURE_PRECISION 9

    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    DeviceAddress insideThermometer, outsideThermometer;
    float teplota;
    String termOUT;
    String termIN;


    #define SCKLED 5


    const char *ssid = "SSID";
    const char *password = "PASSWORD";
    MDNSResponder mdns;

    ESP8266WebServer server(80);
    const int led = 13;



    //pro server
    void handleRoot()
    {
    digitalWrite(SCKLED, 1);
    char temp[450];
    int sec = millis() / 1000;
    int min = sec / 60;
    int hr = min / 60;
    uint8 index = termOUT.indexOf('.');
    int restOUT = termOUT.substring(index+1).toInt();
    int temperatureOUT = termOUT.toInt();
    index = termIN.indexOf('.');
    int restIN = termIN.substring(index + 1).toInt();
    int temperatureIN = termIN.toInt();


    snprintf(temp, 450,

    "<html>\
    <head>\
    <meta http-equiv='refresh' content='5'/>\
    <title>ESP8266 Demo</title>\
    <style>\
    body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    </style>\
    </head>\
    <body>\
    <h1>Teplota v Kuncicich pod Ondrejnikem</h1>\
    <p>Uptime: %02d:%02d:%02d</p>\
    <p>Teplota venku: %02d.%01d°C</p>\
    <p>Teplota doma: %02d.%01d°C</p>\
    </body>\
    </html>",

    hr, min % 60, sec % 60, temperatureOUT,restOUT,temperatureIN,restIN
    );
    server.send(200, "text/html", temp);
    digitalWrite(led, 0);
    }

    void handleNotFound() {
    digitalWrite(led, 1);
    String message = "File Not Found\n\n";
    message += "URI: ";
    message += server.uri();
    message += "\nMethod: ";
    message += (server.method() == HTTP_GET) ? "GET" : "POST";
    message += "\nArguments: ";
    message += server.args();
    message += "\n";

    for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
    }

    server.send(404, "text/plain", message);
    digitalWrite(led, 0);
    }

    void setup(void)
    {

    pinMode(led, OUTPUT);
    pinMode(SCKLED,OUTPUT);
    digitalWrite(SCKLED,LOW);
    digitalWrite(led, 0);
    Serial.begin(9600);
    WiFi.begin(ssid, password);
    Serial.println("");

    // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    }

    Serial.println("");
    Serial.print("Connected to ");
    Serial.println(ssid);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());

    if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
    }

    server.on("/", handleRoot);
    server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");
    });
    server.onNotFound(handleNotFound);
    server.begin();
    Serial.println("HTTP server started");
    //digitalWrite(SCKLED, HIGH);

    //teploměry
    sensors.begin();
    Serial.println("***************************************************");
    Serial.print("Pocet teplomeru: ");
    Serial.println(sensors.getDeviceCount(), DEC);
    //zjisti adresy
    oneWire.reset_search();
    if (!oneWire.search(insideThermometer)) Serial.println("Vnitrni teplomer nenalezen!");
    if (!oneWire.search(outsideThermometer)) Serial.println("Vnejsi teplomer nenalezen!");
    Serial.print("Adresa teplomeru 1: ");
    printAddress(insideThermometer);
    Serial.println();

    Serial.print("Adresa teplomeru 2: ");
    printAddress(outsideThermometer);
    Serial.println();

    //nastav rozlišení
    sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
    sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);

    //načti všechny teploměry
    sensors.requestTemperatures();

    //vytiskni data na seriák
    printData(insideThermometer);
    printData(outsideThermometer);

    }


    void loop(void)
    {
    digitalWrite(led, LOW);
    mdns.update();
    server.handleClient();
    sensors.requestTemperatures();
    teplota = sensors.getTempC(insideThermometer);
    digitalWrite(led, HIGH);
    termOUT = String(teplota, 1);
    teplota = sensors.getTempC(outsideThermometer);
    termIN = String(teplota, 1);
    digitalWrite(led, LOW);

    }

    //pro teploměry
    void printAddress(DeviceAddress deviceAddress)
    {
    for (uint8_t i = 0; i < 8; i++)
    {
    // zero pad the address if necessary
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
    }
    }

    void printData(DeviceAddress deviceAddress)
    {
    Serial.print("Adresa teplomeru ");
    printAddress(deviceAddress);
    Serial.print(":");
    printTemperature(deviceAddress);
    }

    void printTemperature(DeviceAddress deviceAddress)
    {
    float tempC = sensors.getTempC(deviceAddress);
    Serial.print("Teplota: ");
    Serial.print(tempC);
    Serial.write(176);
    Serial.println("C");
    }

    A 137. sorban declaraciós hibát dob, mit kellene átírnom?

    [ Módosította: MurdR ]

    Your Workout Is My Warm-Up so Shut The Fuck Up And Train

Új hozzászólás Aktív témák