2
0

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.

SPRESENSE LTE拡張ボードからTwitterを利用する

Posted at

SPRESENSEデバイスからLTE越しにツイートするライブラリを作成しました。

Twitterアカウントの作成

既存のアカウントを使用することもできますが、ここではいつ凍結されても良いように専用のTwitterアカウントを作成します。
Twitterアカウントを作成するのに別のメールアドレスを用意するのが面倒だな~と思っていたのですが、こんな方法がありました。
Twitterアカウントの複数作成をひとつのメールアドレスで!?

Twitterトークンの取得

StewGate U のサイトへさきほど作成した Twitter アカウントでログインし、連携アプリとして認証します。
この作業により、Twitter トークンを入手することができます。OAuth という仕組みを使っています。

ちなみに認証解除したいときは、Twitter->もっと見る->アカウント->アプリとセッション->StewGate U->アクセス権を取り消す、から解除可能です。

Twitterライブラリ

Stewitter をベースにして、Spresense LTE 用の Twitter ライブラリを作成しました。
https://github.com/baggio63446333/SpresenseLteTwitter

Arduino の libraries 以下にインストールして使ってください。

SimplePost サンプルスケッチ

SpresenseLteTwitter->SimplePost のサンプルスケッチを用意しました。

使用している SIM 環境に合わせて APN 情報を変更してください。

SimplePost.ino
// APN data
# define LTE_APN       "apn"      // replace your APN
# define LTE_USER_NAME "user"     // replace with your username
# define LTE_PASSWORD  "password" // replace with your password

"YourToken" を先ほど取得した Twitter トークンに置き換えてください。

SimplePost.ino
SpresenseLteTwitter twitter("YourToken");

"msg" はツイートの本文です。自由に書き換えてください。

SimplePost.ino
char msg[] = "Hello, World! I'm Spresense!";

繰り返し同一のツイートが禁止されていたり、時間あたりのツイート回数に制限等があったりするのでつぶやきすぎにはご注意ください。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?