あなたのコードにPDPコンテキスト設定がありません。何年も前、私はこの初期化シーケンスが動作することを理解しました(つまり、connectToInternetを拡張します)。
//--if autobauding was enabled, send a blank AT
command:='AT';
send_gprs;
//--switch to minimal mode - this is required to reset the SIM card
command:='AT+CFUN=0';
send_gprs;
//--set dce speed
command:='AT+IPR=57600';
send_gprs;
//--turn off command echo
command:='ATE0';
send_gprs;
//--turn off command echo again - sometimes the first command is ignored
command:='ATE0';
send_gprs;
//--turn on extended error messages
command:='AT+CMEE=1';
send_gprs;
//--set module to full function
command:='AT+CFUN=1';
send_gprs;
SIMカードのロックを解除することが非常に重要です。最も簡単な解決策は、PINリクエストを無効にすることです(実際の電話機にSIMを置き、電話機を使用してこれを設定します)。
//--check pin
command:='AT+CPIN?';
send_gprs;
//--right answer is +CPIN: READY
//--wrong answer is +CME ERROR: 772
次に、APNを設定します。これは実際に非同期APN要求を開始し、AT + CSTTがOKに戻るまで続行しません。
repeat
//--reset connection
command:='AT+CIPSHUT';
send_gprs;
//--set GPRS APN
command:='AT+CSTT="internet.vodafone.net"';
send_gprs;
until is_ok=1;
最後に、GPRS接続を開きます:
repeat
//--Open gprs connection
command:='AT+CIICR';
send_gprs;
//--Get local address - for some reason this is required
command:='AT+CIFSR';
send_gprs;
//--Suppress "SEND OK" after at+cipsend
command:='AT+CIPSPRT=2';
send_gprs;
until is_ok=1;
(申し訳ありませんが、このコードはパスカルで、特にゴールデンではありませんが、コマンドのシーケンスについての注意点があります)。
2つの非常に重要なこと:
- どのコマンドも失敗する可能性があります。ATコマンドへの応答をコンソールウィンドウに返すことをお勧めします。
- AT + CIFSRは悪です。正しい順序でAT + CIFSRを使用しない場合、通信は単に機能しません。私はSIM900Dモジュールを使用していました。あなたのIPを取得することはオプションであると感じるかもしれませんが、何らかの理由で実際にはオプションではありません。
実際のデータ通信にはAT + CIPSENDを使用していました。 HTTPはとても簡単で、制御する方が良いです。