roboforum.ru

Технический форум по робототехнике.

Tiny GPS vs POST-запрос SIM900 GPRS

Как собрать и запрограммировать робота на Arduino(Freeduino, Roboduino, Seeduino ...). Используем Wiring и Processing.

Tiny GPS vs POST-запрос SIM900 GPRS

Сообщение staffnz » 15 июн 2015, 14:59

Забавная ситуация. Есть исправный код для отсылки POST-запроса на сервер через SIM900 GSM.
Добавляю в код только одну строку "TinyGPSPlus gps; " - сразу после этого POST-запрос не формируется. Может TinyGPSPlus перехватывает управление RX TX для SIM900 GSM?


Код: Выделить всёРазвернуть

#include "SIM900.h"
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include "inetGSM.h"
InetGSM inet;

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to start a connection as client.


//CallGSM call;
//SMSGSM sms;
//static const int RXPin = 5, TXPin = 6;
//static const uint32_t GPSBaud = 9600;
//double gpslat;

  String double2string(double n, int ndec){
    String r = "";
    int v = n;
    r += v;     // whole number part
    r += '.';   // decimal point
    int i;
    for (i=0;i<ndec;i++) {
        // iterate through each decimal digit for 0..ndec
        n -= v;
        n *= 10;
        v = n;
        r += v;
    }
    return r;
};
String ltd, lnd;
char msg[50];
int numdata;
char inSerial[50];
int i=0;
boolean started=false;

// The TinyGPS++ object
    TinyGPSPlus gps;
   
// The serial connection to the GPS device
//SoftwareSerial ss(RXPin, TXPin);

void setup()
{digitalWrite(9, HIGH);
Serial.begin(9600);
//ss.begin(GPSBaud);
  //Serial connection.
};

void loop()
{
  ltd = (double2string (44.391922, 5));
  lnd = (double2string (33.794126, 5));
  //Read for new byte on serial hardware,
  //and write them on NewSoftSerial.
// serialhwread();
  //Read for new byte on NewSoftSerial.
// serialswread();
//SoftwareSerial ss(7,8);
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
  if (gsm.begin(2400)){
    Serial.println("\nstatus=READY");
    started=true;
  }
  else
  digitalWrite(9, HIGH);
  Serial.println("\nstatus=IDLE");

  if(started){
    //GPRS attach, put in order APN, username and password.
    //If no needed auth let them blank.
    if (inet.attachGPRS("internet.beeline.ru", "", ""))
      Serial.println("status=ATTACHED");
    else
     digitalWrite(9, HIGH);
      Serial.println("status=ERROR");
    delay(1000);

    //Read IP address.
    gsm.SimpleWriteln("AT+CIFSR");
    delay(5000);
    //Read until serial buffer is emapty.
    gsm.WhileSimpleRead();


String str = "{\"title\":\"temp31\", \"temperature\": \"";
  str += 5;
  str += "\",\"latitude\":\"";
  str += ltd;
  str += "\",\"longitude\":\"";
  str += lnd;
  str += "\", \"device_id\":\"";
  str += 5;
  str += "\"}";
  int len = str.length()+1;
  unsigned char* buf = new unsigned char[len];
  str.getBytes(buf, len, 0);
  Serial.println((const char*)buf);
  numdata=inet.httpPOST("m-ark.kps-dev.com", 80, "/temperature ", (const char*)buf, msg, 50);
  delete buf;

    //TCP Client GET, send a GET request to the server and
    //save the reply.
   // numdata=inet.httpPOST("m-ark.kps-dev.com", 80, "/temperature ", "{\"title\":\"temp38\", \"temperature\": \"25\", \"latitude\":\"55.407749\",\"longitude\":\"38.866600\", \"device_id\":\"28\"}",msg,50);
    //Print the results.
    Serial.println("\nNumber of data received:");
    Serial.println(numdata);
    Serial.println("\nData received:");
    Serial.println(msg);

  }
};
staffnz
 
Сообщения: 8
Зарегистрирован: 02 апр 2015, 23:11

Вернуться в Arduino и другие Xduino

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 0

cron