ใช้โค้ด Water flow sensor D18B20 ต่อกับ ESP8266 แล้วค่าไม่ออกค่ะ มีวิธีแก้ไขไหมคะ

#include <AuthClient.h>
#include <MicroGear.h>
#include <MQTTClient.h>
#include <SHA1.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <EEPROM.h>


const char* ssid = "4G-UFI-611453";
const char* password = "12345678";



#define APPID       "TEMPNAJA"
#define GEARKEY     "gdKNYKDHi1v3vdP"
#define GEARSECRET  "wHIfW197XvMRVWOFSlBcXWzMV"
#define SCOPE       ""


//datasources["currentapps"]["/1066/gearname"].split(",")[0]
//datasources["currentapps"]["/1066/gearname"].split(",")[2]
//datasources["currentapps"]["/1066/gearname/webapp"].split(",")[0]

//datasources["1079DSDATA"]["/1079DS/gearname/webapp"].split(",")[0]

float tempc;
float tempf;

WiFiClient client;
AuthClient *authclient;

int timer = 0;
MicroGear microgear(client);

void onConnected(char *attribute, uint8_t* msg, unsigned int msglen) {
  Serial.println("Connected to NETPIE...");
  microgear.setName("piesensor");
}

volatile int flow_frequency;
unsigned int l_hour, f_val;
unsigned long ctTime, flow_val, cloopTime;

const int ledStatus = 13 ;

void flowLogic() {
  l_hour = (flow_frequency * 60 / 7.5);
  flow_frequency = 0;
  Serial.print("Water Sensor : ");
  Serial.print(l_hour, DEC);
  Serial.print(" L/hour");
  Serial.println("");

  if (l_hour >= 10) {
    digitalWrite(ledStatus, HIGH);
  }
  else if (l_hour < 10) {
    digitalWrite(ledStatus, LOW);
  }

}

void flow () //  Water flow Interrupt function
{
  flow_frequency++;  f_val++;
}

void setup() {
  Serial.begin(9600);
  Serial.println("Micro Project Thailand ^.^ ");
  attachInterrupt(0, flow, RISING);  sei();   ctTime = millis();  cloopTime = ctTime; // Water flow

  pinMode(ledStatus, OUTPUT);
}

void loop () {
  ctTime = millis();
  if (ctTime >= (cloopTime + 1000)) {
    cloopTime = ctTime;
    flowLogic();
  }
}

โด้ตนี้มีการเชื่อม กับ NETPIE ด้วยป่ะครับ เหมือนว่ามันไป error ตอนเชื่อมกับ NETPIE ก่อน ลองถอดชุดเชื่อม NETPIE ออกก่อน ว่ามันอ่านได้ไหม อ่านได้ค่อยเชื่อมครับ

ตอนเอา Netpie ออกโค้ดเชื่อมได้ปกติเลยค่ะ พอใส่ Netpie เลย error ค่ะ อาจารย์พอจะมีวิธีแก้/แนะนำโค้ด ตอนใส่ netpie ไหมคะ พอดีหนูกำลังทำโปรเจค แต่ไม่ค่อยมีใครทำเลยค่ะ

เยี่ยมครับ ทีนี้เราต้องแยกออกเป็น 2 ทางก่อน

  1. คือโค้ตชุดที่เชื่อมอุปกรณ์
  2. โค้ตที่เชื่อมต่อ NETPIE เพียวๆ

ทั้ง 2 แนวทางทำให้เสร็จในแนวของมันก็ก็คือ

แนวทางที่ 1 เชื่อมอุปกรณ์ ครบแล้วอ่านได้ทุกค่าแล้ว ไม่มี error คือ Offline
แนวทางที่ 2 เชื่อม NETPIE ให้ได้ Online ได้แล้ว

จากนั้นเราก็นำทั้ง 2 แนวทางรวมกัน มันก็จะควบคุมได้ว่า ทั้ง 2 ชุดไม่มี error แน่ๆ

เอาจริงๆ ส่วนตัวผมไม่เคยเล่น NETPIE นะครับ ถ้าเป็นเชิงลึงผมส่งต่อเข้าไปที่ กลุ่มเขาโดยตรงเลยดีกว่า ได้ความคืบหน้ายังไง เอามาอัพเดทกันครับ หรือจะให้ช่วยดู error ส่วนอื่นก็ตั้งกระทู้ถามในนี้ได้เลย

ขอบคุณมากค่ะอาจารย์ ถ้าทำได้แล้วหนูจะมาอัพเดทนะคะ

1 Likes