ความรู้แน่น ฟรีสำหรับชุมชน ArduinoAll ที่นี่เท่านั้น

ฟรีและดีที่สุด คอร์สอบรม Arduino + NodeMCU
ทำเพื่อแบ่งปัน ห้ามนำไปจำหน่าย หรือเก็บเงินค่าเรียน
  !!!


  


AllNewStep รับประกันคุณภาพทุกชิ้น วันจันทร์-ศุกร์แจ้งชำระสินค้าก่อน 14.00 จัดส่งทันทีวันนี้ค่ะ

กรุงเทพ /ภาคกลาง ได้พรุ่งนี้


*** สินค้าทุกชิ้น ถ้าสามารถทำรายการสั่งซื้อได้ แสดงว่ามีครบทุกรายการค่ะ *** 

พิมพ์ค้นหาบทความ หัวข้อกระทู้ และสินค้าในเว็บ AllNewStep ได้ที่นี่
QUOTE 

สอบถามครับ GPS

บอส

ผมส่งค่าจาก Sensor 4 ขึ้น netpie ทั้ง 3 sensor ปกติ แต่ค่า GPS ไม่ขึ้นครับ

แต่ถ้าเขียน code ให้ส่งค่า GPS อย่างเดียว สามารถส่งค่าขึ้นได้ครับ ไม่ทราบว่ามันมีเงื่อนไขอะไรไหมตรงไหนผมผิดไปขอความช่วยเหลือหน่อยครับ

 

code 

#include <ESP8266WiFi.h>

#include "TinyGPS++.h"

#include "SoftwareSerial.h"

#include <MicroGear.h>

#include "DHT.h"

#include <MCP3008.h>

#include <time.h>

 

const char* ssid     = "********";

const char* password = "*********";

 

SoftwareSerial serial_connection(D7, D8); 

TinyGPSPlus gps;

 

#define DHTPIN D1

#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

 

#define APPID   "Gas"

#define KEY     "nmGDsgKbcs9HNaI"

#define SECRET  "AnhBaAT5R00BvI6FLUREIvZnB" 

#define ALIAS   "NODEMCU"

 

#define CS_PIN D4

#define CLOCK_PIN D5

#define MOSI_PIN D3

#define MISO_PIN D6

MCP3008 adc(CLOCK_PIN, MOSI_PIN, MISO_PIN, CS_PIN);

 

int dustPin=A0;

int dustVal=0;

int ledPower=D2;

int delayTime=280;

int delayTime2=40;

float offTime=9680;

 

WiFiClient client;

MicroGear microgear(client);

 

void onConnected(char *attribute, uint8_t* msg, unsigned int msglen) {

    Serial.println("Connected to NETPIE...");

    /* Set the alias of this microgear ALIAS */

    microgear.setAlias(ALIAS);

}

 

void setup() {

    microgear.on(CONNECTED,onConnected);

    Serial.begin(115200);

    Serial.println("GPS Start");

    serial_connection.begin(9600);//This opens up communications to the GPS

    Serial.println("Starting...");

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) 

    {

      delay(250);

      Serial.print(".");

    }

    Serial.println("WiFi connected");  

    Serial.println("IP address: ");

    Serial.println(WiFi.localIP());

    microgear.init(KEY,SECRET,ALIAS);

    microgear.connect(APPID);

    dht.begin();

}

void Temphum()

{

    float h = dht.readHumidity();

    float t = dht.readTemperature();

    if (isnan(t) || isnan(h)) {

        return;

    }

    microgear.publish("/Temp",int(t));

    microgear.publish("/Hum",int(h));

    Serial.println("TempHum Send");

 

}

void Gps()

{

    while(serial_connection.available())//While there are characters to come from the GPS

    {

        gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time

    }

    if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in

    {

    microgear.publish("/Lat",gps.location.lat(), 6);

    microgear.publish("/Long",gps.location.lng(), 6); 

    }

}

 

void Gas()

{

    float vol; 

    float sensorValue = adc.readADC(0); 

    vol=(float)sensorValue/1024*100.0; 

    microgear.publish("/Gas",int(vol));

}

 

void Dust()

{

    digitalWrite(ledPower,LOW);// power on the LED

    delayMicroseconds(delayTime);

    dustVal=analogRead(dustPin);// read the dust value via pin 5 on the sensor

    delayMicroseconds(delayTime2);

    digitalWrite(ledPower,HIGH);// turn the LED off

    delayMicroseconds(offTime);

    microgear.publish("/Dust",float(dustVal));

}

 

void loop() {

    if (microgear.connected()) {

    microgear.loop();

    Gps();

    Temphum();

    Gas();

    Dust();

  

    delay(1000);

    }

    else 

    {

    microgear.connect(APPID);

    }

}

 

QUOTE 
ความคิดเห็นที่ #1
เจ้าของร้าน

จากโคดดูแล้วไม่น่าจะมีปัญหา อาจจะติดปัญหาบางอย่างต้องลอง debug โดคเพิ่มเติม ให้เช็คที่คำสั่ง gps น่าจะมาจาก gps ยังรับสัญญาณไม่ได้ครับ 

 

แสดงความคิดเห็นที่ 1-1 จากทั้งหมด 1 ความคิดเห็น
ขาย ARDUINO
คุณภาพ อันดับ 1

ได้รับรางวัลร้านยอดเยี่ยม
ตั้งแต่ปี 2558
ขาย Arduino
วีดีโอสอน Arduino

สอน esp8266

สอน Arduino IoT
สอน Arduino แบบเร็ว

สอน NodeMCU

อุปกรณ์ Arduino

MEMBER ZONE

พูดคุย-สอบถาม