Chat freely about anything...

User avatar
By Jptalon
#37057 Hello
I have the wemos d1 board with an adafruit one wire thermocouple.
Can someone help me with modifying my sketch?
I do not understand yet the gpio setup and placements yet so that I dont mess up the booting.
The code below works and gets a hardcoded temp to my server.
Now I just need to get the onewire into the mix but after hours of reading, i dont see where people are switching the pinmode.
Thanks and any tips are greatly appreciated.

Code: Select all#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;

void setup() {

    USE_SERIAL.begin(115200);
   // USE_SERIAL.setDebugOutput(true);

    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();

    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }

    WiFiMulti.addAP("DD-WRT", "********");

}

void loop() {
    // wait for WiFi connection
    if((WiFiMulti.run() == WL_CONNECTED)) {

        HTTPClient http;

        USE_SERIAL.print("[HTTP] begin...\n");
         http.begin("www.****.com", 80, "/temp/select.php?t=125"); //HTTP

        USE_SERIAL.print("[HTTP] GET...\n");
        // start connection and send HTTP header
        int httpCode = http.GET();
        if(httpCode) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == 200) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
        }
    }

    delay(10000);
}
User avatar
By GengusKahn
#37061 Hi there, I do not have your setup so this is not verified by the IDE but there should be no problem, other than the Pin Selection make sure this is correct.....

Code: Select all#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
// Added................
//♀♪♫☼♂

#include <OneWire.h>     // Used for temperature sensor(s)
#include <DallasTemperature.h>  // Specific for temperature sensors
OneWire oneWire(2);       // This is the pin for the DS18B20 Remeber the pullup Resistor if not using a breakout.
DallasTemperature sensors(&oneWire);
float pT;

//..................

#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;

void setup() {

    USE_SERIAL.begin(115200);
   // USE_SERIAL.setDebugOutput(true);

// Added................
//♀♪♫☼♂

  sensors.begin();
  oneWire.reset_search();
  delay(50);
  sensors.requestTemperatures();
  pT=(sensors.getTempCByIndex(0));// This is the first sensor add more lines for more sensors eg... pT1=(sensors.getTempCByIndex(1));

//  Temperature is now in pT variable as floating point.......

//................................

    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();

    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }

    WiFiMulti.addAP("DD-WRT", "********");

}

void loop() {
    // wait for WiFi connection
    if((WiFiMulti.run() == WL_CONNECTED)) {

        HTTPClient http;

        USE_SERIAL.print("[HTTP] begin...\n");

// Added................
//♀♪♫☼♂

        sensors.requestTemperatures();
        pT=(sensors.getTempCByIndex(0));// This is the first sensor add more lines for more sensors eg... pT1=(sensors.getTempCByIndex(1));
        String message = "/temp/select.php?t=";
               message += pT;
         http.begin("www.****.com", 80, message); //HTTP  This has the "message" constructed from the String + float

//................

        USE_SERIAL.print("[HTTP] GET...\n");
        // start connection and send HTTP header
        int httpCode = http.GET();
        if(httpCode) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == 200) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
        }
    }

    delay(10000);
}

User avatar
By GengusKahn
#37070 Hi there, the boot process is already complete by the time the sketch is executed, the boot is "Helped" by the pull up resistor on the DS18B20 as the normal boot mode requires this pin to be high....

Look at the posts I have made about Thingspeak and Freeboard.io to give the readings some visual appeal......