2017年5月27日 星期六

LinkIt ONE: GPRS 連接 + HTTP Request

LinkIt ONE 只支援 2G 的基地台訊號,若要使用 GPRS 一定要確認電信是否是 2G ,且提供 GPRS 功能,統一超商電信資費方案似乎有支援。

設置天線

請將 GSM 天線設置在模組上。

Arduino

/*
  Web client

 This sketch connects to a website through GPRS on LinkIt platform. 
 Specifically,
 this example downloads the URL "http://arduino.cc/asciilogo.txt" and
 prints it to the Serial monitor.

 created 8 Mar 2012
 by Tom Igoe
 Modified 20 Aug 2014
 by MediaTek Inc.

 */


#include <LGPRS.h>
#include <LGPRSClient.h>
#include <LGPRSServer.h>

char server[] = "jsonplaceholder.typicode.com"; //主機 HOST, 注意這個不是網址
char path[] = "/posts/1"; //主機後面的訪問路徑
int port = 80; // HTTP

LGPRSClient client;

void setup()
{
  // setup Serial po
  Serial.begin(115200);

  Serial.println("Attach to GPRS network by auto-detect APN setting");
  while (!LGPRS.attachGPRS())
  {
    delay(5000);
  }

  // if you get a connection, report back via serial:
  Serial.print("Connect to ");
  Serial.println(server);
  if (client.connect(server, port))
  {
    Serial.println("connected");
    // Make a HTTP request:
    client.print("GET ");
    client.print(path);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
  }
  else
  {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected())
  {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for (;;)
      ;
  }
}

Reference:
http://www.instructables.com/id/LinkIt-ONE-SMS-Tutorial/#step4
http://blog.cavedu.com/%E7%89%A9%E8%81%AF%E7%B6%B2/linkit/linkit-one-%E6%95%99%E5%AD%B8-linkit-one-%E7%B4%80%E9%8C%84-gps-%E9%BB%9E%E6%96%BC-mediatek-sandbox-%EF%BC%88%E5%AF%A6%E6%B8%AC%E6%96%BC%E5%8F%B0%E5%8C%97-%E6%AD%A6%E9%99%B5%E8%BE%B2%E5%A0%B4/
http://blog.xuite.net/m0923678421/development/326740873-LinkIt+ONE+%E9%96%8B%E7%99%BC%E6%9D%BF+%E7%9B%B8%E5%AE%B9Arduino+GPS+%E8%97%8D%E7%89%99+WIFI+GSM+GPRS
http://www.robocon.com.tw/272312212020154blog/linkit-onegsmgprsled
https://www.7-11.com.tw/ibonmobile/act1_2.html

沒有留言:

張貼留言

© Mac Taylor, 歡迎自由轉貼。
Background Email Pattern by Toby Elliott
Since 2014