LoginSignup
6
2

More than 5 years have passed since last update.

Ntrip Client for ESP32

Last updated at Posted at 2019-02-02

概略

F9P-BT-Rover_tabletesp8266 (1).jpg

F9Pも出た事だし

ESP32のWiFiでRTCM3を拾ってきて、M8PとかF9Pに投げれたら最高よねえ・・。
とか妄想してたら、ソースコードを公開している方がいました。
この場を借りて感謝を伝えたいと思います。

トラ技キット

Bluetooth SPPについて

せっかくシリアルのRXDが空いてるしBluetoothも内蔵してるから・・と、BluetoothSerial.hを使ってみましたが、データ途切れるしフリーズするし、そのままでは使い物にならないです。(2019/2現時点)

ボードに組んでみた。

テスト段階では16時間ほど動きました。
データ取りしてなかったので寝てたり他の作業している間の挙動とかはわからないけれど、フリーズせずに稼働していました。
電源部分の回路は秋月電子のESP8266の回路図を参考にしました。
http://akizukidenshi.com/catalog/g/gK-12236/

部品表

秋月電子で買えるものは[通販コード]として記述しました。
トラ技のM8P
コード付きシガーソケット
ターミナル2P[P-01306]
RN42[M-07612]
3端子レギュレータ[I-08678]
放熱器[P-05052]
アルミ個体コンデンサ[P-09475]
三端子レギュレータ[I-11299]
ショットキーバリアダイオード[I-05951]
DIPスイッチ4P[P-08923]
チップ積層セラミックコンデンサ[P-13374]
電解コンデンサ[P-03177]
抵抗器 470オーム*2,10kオーム*4
RN42[K-07378]
UEW線 0.2mm 少々 注意:90mAぐらいまでしか流せません。
スズメッキ線 0.6mm 少々
ピンヘッダー 少々
ユニバーサル基板
ボタンスイッチ 2個

IMG_4138.jpeg

Ambientに送るようにしてみた

ネタ元はココ。

ESP8266のRXDにNMEAを流す必要があります。
現状直結してますが、電気的にこれで良いのかはわかりません。ご助言いただけたら助かります。
(ほぼコピペのキメラ状態)

ソース
NTRIPClient_ambient_beta01.ino

/*
 *  NTRIP client for Arduino Ver. 1.0.0 
 *  NTRIPClient Sample
 *  Request Source Table (Source Table is basestation list in NTRIP Caster)
 *  Request Reference Data 
 * 
 * 
 */
 /*
 add AMBIENT
 */

#include <ESP8266WiFi.h>  //Need for ESP8266
//#include <WiFi.h>           //Need for ESP32 
#include "NTRIPClient.h"
#include <TinyGPS++.h>
#include "Ambient.h"

const char* ssid     = "your_ssid";
const char* password = "your_password";

char* host = "ntrip caster host";
int httpPort = 2101; //port 2101 is default port of NTRIP caster
char* mntpnt = "ntrip caster's mountpoint";
char* user   = "ntrip caster's client user";
char* passwd = "ntrip caster's client password";

NTRIPClient ntrip_c;

WiFiClient connect2;
extern "C" {
#include "user_interface.h"
}

unsigned int channelId = 100;
const char* writeKey = "ライトキー";

TinyGPSPlus gps;
void sendInfo2Ambient();

Ambient ambient;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(19200);
  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  Serial.println("Requesting SourceTable.");
  if(ntrip_c.reqSrcTbl(host,httpPort)){
    char buffer[512];
    delay(5);
    while(ntrip_c.available()){
      ntrip_c.readLine(buffer,sizeof(buffer));
      Serial.print(buffer); 
    }
  }
  else{
    Serial.println("SourceTable request error");
  }
  Serial.print("Requesting SourceTable is OK\n");
  ntrip_c.stop(); //Need to call "stop" function for next request.

  Serial.println("Requesting MountPoint's Raw data");
  if(!ntrip_c.reqRaw(host,httpPort,mntpnt,user,passwd)){
    delay(15000);
    ESP.restart();
  }
  Serial.println("Requesting MountPoint is OK");
   ambient.begin(channelId, writeKey, &connect2 );

}

void loop() {

  // put your main code here, to run repeatedly:
   while(ntrip_c.available()) {
    char ch = ntrip_c.read();        
    Serial.print(ch);
   }  

       if (gps.location.isValid()) {
            sendInfo2Ambient();
        }
        while (Serial.available() > 0) {
          if (gps.encode(Serial.read())) {
        break;
        }
    }

}

void sendInfo2Ambient() {
    char buf[16];
    if (gps.location.isValid()) {
        dtostrf(gps.altitude.meters(), 4, 2, buf);      
        ambient.set(1, buf);
        dtostrf(gps.location.lat(), 12, 8, buf);
        ambient.set(9, buf);
        dtostrf(gps.location.lng(), 12, 8, buf);
        ambient.set(10, buf);
        ambient.send();
    }
}

F9P-BT-Rover_tabletesp8266 (2).jpg

6
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
6
2