One Wire วัดอุณหภูมิ แบริ่ง มอเตอร์ พัดลม

เป็นการทดสอบการต่อ  OneWire  4 ตัว  เข้าที่ขา 4   และ  14  ขาละ  2 ตัว

/*
 *  This sketch sends data via HTTP GET requests to data.sparkfun.com service.
 *
 *  You need to get streamId and privateKey at data.sparkfun.com and paste them
 *  below. Or just customize this script to talk to other HTTP servers.
 *  Set board NodeMCU-32S pr ESP32 Dev Module
 *  Set Programmer AVRISP mkll
 */

// Use 3V3 GIOP 2 ESP32 Dev Module 
// Programmer AVRSIP mkll


#include <Adafruit_Sensor.h>

/*********
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com  
*********/

#include <OneWire.h>
#include <DallasTemperature.h>

// GPIO where the DS18B20 is connected to
const int oneWireBus1 = 4;     
const int oneWireBus2 = 14; 

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire1(oneWireBus1);
OneWire oneWire2(oneWireBus2);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors1(&oneWire1);
DallasTemperature sensors2(&oneWire2);



//=========
#include <WiFi.h>
//======

 //====
//const char* ssid     = "AndridsfsdodAP";
//const char* password = "nhdlsdfsd8613";
//const char* ssid     = "Arsesdfsdnalsdfsd2019_2.4G";
//const char* password = "kb75699sdfsd212";
const char* ssid     = "dlsddfsdfink_DfddWR-932C_0C4E";
const char* password = "gkyVD3sdfs5784";
//const char* ssid     = "AndrdfsdfoidAP-J7";
//const char* password = "brasfsdfw5645";

const char* host = "otrixiot.com";
const char* code = "xxx-xxx";
const char* dID = "xxx";
float tempC_0 = 0;
float tempF_0=0;
float fan_c = 0;
float fan_f =0;
float pulley_c=0;
float pulley_f=0;

float motor_NDE_c =0;
float motor_NDE_f=0;
float motor_DE_c=0;
float motor_DE_f=0;

float humid_0 = 0;
float vHumidity = 0;
float vTemperature = 0;
float data1=0;
float data2=0;
float data3=0;
float data4=0;
float data5=0;
float data6=0;
float data7=0;
float data8=0;
float data9=0;
float data10=0;
float data11=0;
float data12=0;
float data13=0;
float data14=0;
float data15=0;
float data16=0;
float data17=0;
float data18=0;
float data19=0;
float data20=0;
float temperatureC=30;
float temperatureF=75;

/*
void setup_Sensor_Box_Temperature()
{
  dht.begin();
}
*/
/// ===
void ds18b20_setup() 
{
  // Start the Serial Monitor
  Serial.begin(115200);
  // Start the DS18B20 sensor
  sensors1.begin(); 
  sensors2.begin(); 
}


// Main setup ========
void setup()
{
    Serial.begin(115200);
    ds18b20_setup();      
    delay(10);

    // We start by connecting to a WiFi network

    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

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

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
}

int value = 0;

void loop()
{
    delay(5000);
    ds18b20_loop();
//    scanSensor_Box_Temperature();
    //data1 = vTemperature;
    ++value;
    data1 = fan_c;
    data2 = pulley_c;
    data3 = motor_NDE_c;
    data4 = motor_DE_c;
   
    Serial.print("connecting to ");
    Serial.println(host);

    // Use WiFiClient class to create TCP connections
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
        Serial.println("connection failed");
        return;
    }

    // We now create a URI for the request
     String url = "/api/insesdcsdrtData?device_id=" + String(dID)+"&code="+String(code)+"&data1=" +String(data1) +"&data2="
   + String(data2)+"&data3=" +String(data3)+"&data4=" +String(data4)+"&data5=" +String(data5)
   +"&data6=" +String(data6)+"&data7=" +String(data7)+"&data8=" +String(data8)+"&data9=" +String(data9)
   +"&data10=" +String(data10)+"&data11=" +String(data11)+"&data12=" +String(data12)+"&data13=" +String(data13)
   +"&data14=" +String(data14)+"&data15=" +String(data15)+"&data16=" +String(data16)+"&data17=" +String(data17)
   +"&data18=" +String(data18)+"&data19=" +String(data19)+"&data20=" +String(data20);   
 
    Serial.print("Requesting URL: ");
    Serial.println(url);

    // This will send the request to the server
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" +
                 "Connection: close\r\n\r\n");
    //unsigned long timeout = millis();
    delay(1000);
    
    while (client.available() == 0) {
            Serial.println(">>> Client Timeout !");
            client.stop();
            return;
           }
    
     

    // Read all the lines of the reply from server and print them to Serial
    while(client.available()) {
        String line = client.readStringUntil('\r');
        //Serial.print(line);
    }

    Serial.println();
    Serial.println("closing connection");
    delay(30000);
}
//====
void ds18b20_loop() 
{
  sensors1.requestTemperatures(); 
  float fanbearing_c = sensors1.getTempCByIndex(0);
  float pulley_bearing_c = sensors1.getTempCByIndex(1);
  float motorNDE_c = sensors2.getTempCByIndex(0);
  float motorDE_c = sensors2.getTempCByIndex(1);  
 
  Serial.print(fanbearing_c);
  Serial.println("ºC");
  Serial.print(pulley_bearing_c);
  Serial.println("ºF");
  delay(5000);  
  fan_c = fanbearing_c;
  pulley_c=pulley_bearing_c;
  motor_NDE_c=motorNDE_c;
  motor_DE_c=motorDE_c;
}

//====

 

450 total views, 1 views today