2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

M5StickCでGPS座標をInfluxDBに記録する

Last updated at Posted at 2020-03-21

GPS座標を記録する

RTKとかでネット必須な環境で、トラクターとかの作業機を使ってると作業記録を付けたくなるので作ってみました。
まだ表示周りは手を付けてないので、メモ代わり。

NMEAの入力は、ソースの中のSerial2.begin(115200,SERIAL_8N1,33,32);
で指定しています。

Influxdbの設定でUDPを有効にする

/etc/influxdb/influxdb.conf
[[udp]]
  # enabled = false
   enabled = true
   bind-address = ":8089"
   database = "test1"

influxdbを再起動

sudo service influxdb restart

データベースを作る

$ influx
CREATE DATABASE test1
quit

ソース

必要なライブラリ
TinyGPS++
http://arduiniana.org/libraries/tinygpsplus/

M5StickC_NMEA_InfluxDB
gps_influx_ds18b20.ino

# include <TinyGPS++.h>
# include <WiFi.h>
# include <WiFiUDP.h>
char ssid[] = "SSID";
const char* password = "password";
// the IP address of your InfluxDB host
byte host[] = {10, 0, 1, 7};
int port = 8089;
WiFiUDP udp;

TinyGPSPlus gps;

void setup()
{
    Serial2.begin(115200,SERIAL_8N1,33,32);
    Serial.begin(115200);
    WiFi.begin(ssid, password); 
    while (WiFi.status() != WL_CONNECTED) { 
    delay(100);
    Serial.print(".");
    }
}

void loop()
{
  uint8_t chipid[6];
  esp_efuse_read_mac(chipid);

  while (Serial2.available() > 0) {
    char c = Serial2.read();
    gps.encode(c);
    if (gps.location.isUpdated()) {
      Serial.print("LAT:  "); Serial.println(gps.location.lat(), 9);
      Serial.print("LONG: "); Serial.println(gps.location.lng(), 9);

  String latnum=String(gps.location.lat(),9);
  String lngnum=String(gps.location.lng(),9);
  String high=String(gps.altitude.meters());
  String id=String(chipid[0],HEX)+String(chipid[1],HEX)+String(chipid[2],HEX)+String(chipid[3],HEX)+String(chipid[4],HEX)+String(chipid[5],HEX);

chipid[1], chipid[2], chipid[3], chipid[4], chipid[5]);
  String line;
  line="gps,device="+id+" lat="+latnum+",lng="+lngnum+",high="+high;
  Serial.println(line);
  Serial.println("Sending UDP packet...");
  udp.beginPacket(host, port);
  udp.print(line);
  udp.endPacket();
  delay(10000);
    }
  }
}

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?