LoginSignup
1
0

More than 5 years have passed since last update.

GR-CITRUSとWA-MIKANでhttpGetのレスポンスをSDカードに保存する、を試す

Posted at
#!mruby
@usb = Serial.new 0
# デバッグ用のpメソッド
def p obj
    @usb.print obj.to_s
end

System.useSD
System.useWiFi

# Station(子機)モードにする
WiFi.setMode 1
WiFi.connect "ssid", "password"
p WiFi.ipconfig
# 複数接続可能モードの設定  mode: 0:1接続のみ, 1:4接続まで可能 らしいがよくわかりません…
WiFi.multiConnect 1
WiFi.httpGetSD "response.txt", "google.com"
WiFi.disconnect

# ファイル番号0としてresponse.txtをReadモード(0)で開く
SD.open 0, "response.txt", 0
# readの引数はファイル番号ファイル番号、返り値はデータ(バイト)、ファイルの最後なら-1
while (c = SD.read(0)) > 0
    p c.chr
end
SD.close 0

httpGetSD.png

無事にhttpGetのレスポンスがSDカードに保存されたのを確認できました

  • メモ
    • 成功した後にファイル名を変えて再実行するとWiFi.httpGetSDが7を返して(7: 受信したファイルの生成に失敗した)、新しくファイルが作成されない。なぜ…
1
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
1
0