GPRS连接到风速计时不发送信息

时间:2019-06-13 18:56:29

标签: arduino

我已将arduino连接到4个不同的模块:

  • RTC
  • GPRS屏蔽(SARA G350)
  • 风向标
  • 风速计

每次启动系统时,除非断开风速计,否则GPRS不会发送任何信息。 我已经尝试过单独使用风速计代码,并且可以正常工作,我认为当连接风速计时,GPRS没有足够的功率来发送数据,但是我不确定。

    #include <SoftwareSerial.h>
    #include <Wire.h>
    #include <ds3231.h>

    struct ts t;
    String Angle;

    int serial_in;


    double x = 0;
    double y = 0;
    double a = 0;
    double b = 0;
    const int sensorPin = A5; 
    const int numReadings = 10;
    int readings[numReadings];     
    int readIndex = 0;             
    int totalWind= 0;                
    int averageWind = 0;           
    int inputPin = A5;
    int sensorValue = 0;
    float sensorVoltage = 0; 
    float sensorVoltage2 = 0;
    float windSpeed = 0; 

    float voltageConversionConstant = .004882814; 
    int sensorDelay = 2000;


    float voltageMin = .4; 
    float windSpeedMin = 0; 

    float voltageMax = 2.0; 
    float windSpeedMax = 32; 

    SoftwareSerial mySerial(2, 3); //Tx & Rx sont connectés aux broches Arduino #7 et #8

    void setup()
    {
      delay(15000);
     Wire.begin();
     DS3231_init(DS3231_INTCN);
     //Commence la communication Serie
     //Commence la communication Serie Arduino-Shield GPRS
      mySerial.begin(9600);
      delay(1000);

  mySerial.println("AT"); //Handshaking
  updateSerial();
  mySerial.println("AT+UPSDA=2,0"); //Reset connexion
    updateSerial();
    delay(2000);
     mySerial.println("AT+UPSD=2,1,\"sl2sfr\""); //Establissement de connexion avec l'APN
    updateSerial();
    delay(2000);
    mySerial.println("AT+UPSDA=2,3"); 
    updateSerial();
    delay(2000);
    mySerial.println("AT+UPSND=2,0");
    updateSerial();
    delay(2000);
}

void loop()
{
  mySerial.println("AT+UPSDA=2,0"); //Reset connexion
    updateSerial();
    delay(2000);
     mySerial.println("AT+UPSD=2,1,\"sl2sfr\""); //Establissement de connexion avec l'APN
    updateSerial();
    delay(2000);
    mySerial.println("AT+UPSDA=2,3"); 
    updateSerial();
    delay(2000);
    mySerial.println("AT+UPSND=2,0");
    updateSerial();
    delay(2000);

   String Equipement = "STAINS";
   mySerial.println("AT+UHTTP=0");
    updateSerial();
    delay(2000);
    mySerial.println("AT+UHTTP=2,1,\"www.projetwmr.site\""); // Parametrage URL d'acces
    updateSerial();              
    delay(2000);
   String command = "AT+UHTTPC=2,5,\"/add.php\",\"post.ffs\",\"vite="; // Commande d'envoi des donnes via POST sur PHP
    anemometre(); // Recuperation des données ANALOGIQUES
    // convertion valeurs en String - Chaîne de caractères
    command += String(windSpeed);
    // or convertion précise
    // command += String(Windspeed, 2);
    command += "&equipement=";
    command += String(Equipement);
     DS3231_get(&t);
   String heure = String(t.hour);
   heure += ":";
   heure += String(t.min);
   heure += ":";
   heure += String(t.sec);
  String Date = String(t.year);
   Date += "-";
   Date += String(t.mon);
   Date += "-";
   Date += String(t.mday);
    command += "&time=";
    command += String(heure);
    command += "&date=";
    command += String(Date);
    command += "&dire=";
    girouette();
    command += String(Angle);
    command += "\",0"; //Fin de la commande PHP POST
    mySerial.println(command);
    updateSerial();
    delay(45000);

}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

void girouette()
{
 int sensorValue = analogRead(A1);
  if (sensorValue >= 89  && sensorValue<=95  )
  {  Angle="0°"; }

    if (sensorValue >=60  && sensorValue<=70  )
  {  Angle="22.5°"; }

    if (sensorValue >=180   && sensorValue<=190  )
  {  Angle="45°"; }


    if (sensorValue >= 124  && sensorValue<=130  )
  {  Angle="67.5°"; }


    if (sensorValue >= 285  && sensorValue<=292  )
  {  Angle="90°"; }


    if (sensorValue >=240   && sensorValue<=250  )
  {  Angle="115.5°"; }


    if (sensorValue >= 630  && sensorValue<=640  )
  {  Angle="135°"; }

    if (sensorValue >= 600  && sensorValue<=610  )
  {  Angle="157.5°"; }

    if (sensorValue >=940  && sensorValue<=952  )
  {  Angle="180°"; }


    if (sensorValue >=825   && sensorValue<= 840 )
  {  Angle="202.5°"; }


    if (sensorValue >= 880  && sensorValue<= 898 )
  {  Angle="225°"; }


    if (sensorValue >= 700  && sensorValue<= 712 )
  {  Angle="247.5°"; }


    if (sensorValue >= 785  && sensorValue<= 795 )
  {  Angle="270°"; }


    if (sensorValue >= 405  && sensorValue<= 415)
  {  Angle="292.5°"; }


    if (sensorValue >= 460  && sensorValue<= 470 )
  {  Angle="315°"; }


    if (sensorValue >= 78  && sensorValue<=87  )
  {  Angle="337.5°"; }


    if (sensorValue >= 1000  && sensorValue<=50  )
  {  Angle="Error"; }

delay(100);
}

void anemometre()
{

  sensorValue = analogRead(A5); 

  totalWind = totalWind - readings[readIndex];

  readings[readIndex] = sensorValue;

  totalWind = totalWind + readings[readIndex];

  readIndex = readIndex + 1;
 sensorVoltage2 = sensorValue * voltageConversionConstant; 
  if (readIndex >= numReadings) {

    readIndex = 0;


  averageWind = totalWind / numReadings;

  sensorVoltage = averageWind * voltageConversionConstant; 


  if (sensorVoltage <= voltageMin) {
    windSpeed = 0; 
  } else {
    windSpeed = ((sensorVoltage - voltageMin) * windSpeedMax / (voltageMax - voltageMin))*1.55; 
  }
  }



  x = windSpeed;
  if (x >= y) {
    y = x;
  } else {
    y = y;
  }



  a = sensorVoltage;
  if (a >= b) {
    b = a;
  } else {
    b = b;
  }
}

1 个答案:

答案 0 :(得分:0)

如果没有理由使用它,则应避免使用 SoftwareSerial ,它效率低下,很可能导致正在加载的其他库出现问题。

请始终使用硬件串行端口(如果有)。有关替代方法,请参见here