Не все данные с последовательного порта Arduino принимаются Thing speak с использованием esp8266 и Arduino Uno. Не могли бы вы ответить, пожалуйста

#esp8266 #arduino-uno #arduino-esp8266 #esp8266wifi

Вопрос:

Я использовал датчик температуры, мутности и рН. (с использованием esp8266 и arduino uno)

Все показания датчиков отображаются в последовательном порту. Не все данные с последовательного порта Arduino принимаются вещью, говорящей с датчиков. Это и есть код

#включить <SoftwareSerial.h>

#включить <OneWire.h>

#включить <DallasTemperature.h>

#определить ONE_WIRE_BUS 2

OneWire OneWire(ONE_WIRE_BUS);

Датчики температуры Dallast (и один провод);

#определите контактный датчик A1

без знака длинное значение int Среднее значение;

поплавок b;

int buf[10],темп;

#определите RX 3

#определите TX 4

Строка AP = «»;

ПРОПУСК строки = «»;

Строковый API = «»;

Строка ХОСТ = «api.thingspeak.com»;

Строковый ПОРТ = «80»;

Строка field1 = «поле 1»;

Строка field2 = «поле 2»;

Строка field3 = «поле 3»;

команда int counttruкоманда;

команда int countTimeCommand;

найдено логическое значение = false;

поплавковый валСенсор1;

поплавковый датчик 2;

поплавковый датчик 3;

Программное обеспечение esp8266(RX,TX);

пустая настройка()

{

 Serial.begin(9600);

pinMode(13,OUTPUT);

sensors.begin();    

esp8266.begin(115200);

sendCommand("AT",5,"OK");

sendCommand("AT CWMODE=1",5,"OK");

sendCommand("AT CWJAP=""  AP  "",""  PASS  """,20,"OK");
 

}

void loop()

{

 valSensor1 = getTemper();

valSensor2 = getTurbidity();

valSensor3 = getpH();

String getData1 = "GET /update?api_key="  API  "amp;"  field1  "=" String(valSensor1);

String getData2 = "GET /update?api_key="  API  "amp;"  field2  "=" String(valSensor2);

String getData3 = "GET /update?api_key="  API  "amp;"  field3  "=" String(valSensor3);

sendCommand("AT CIPMUX=1",5,"OK");
sendCommand("AT CIPSTART=0,"TCP",""  HOST  "","  PORT,15,"OK");
sendCommand("AT CIPSEND=0,"  String(getData1.length() 4),4,">");
esp8266.println(getData1);//delay(1500);countTrueCommand  ;
sendCommand("AT CIPCLOSE=0",5,"OK");

sendCommand("AT CIPMUX=1",5,"OK");
sendCommand("AT CIPSTART=0,"TCP",""  HOST  "","  PORT,15,"OK");
sendCommand("AT CIPSEND=0,"  String(getData2.length() 4),4,">");
esp8266.println(getData2);//delay(1500);countTrueCommand  ;
sendCommand("AT CIPCLOSE=0",5,"OK");

sendCommand("AT CIPMUX=1",5,"OK");
sendCommand("AT CIPSTART=0,"TCP",""  HOST  "","  PORT,15,"OK");
sendCommand("AT CIPSEND=0,"  String(getData3.length() 4),4,">");
esp8266.println(getData3);//delay(1500);countTrueCommand  ;
sendCommand("AT CIPCLOSE=0",5,"OK");
 

}

float getTemper()

{

 sensors.requestTemperatures(); 

//print the temperature in Celsius

Serial.println();

Serial.print("Temperature: ");

int temperature=sensors.getTempCByIndex(0);

Serial.print(temperature);

//Serial.print((char)176);//shows degrees character

Serial.print("C  |  ");

//delay(500);

return temperature; 
 

}

float getTurbidity()

{

 int sensorValue = analogRead(A0);// read the input on analog pin 0:

float voltt = sensorValue * (5.0 / 1024.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):

Serial.print("Turbidity in volts: ");

Serial.print(voltt); // print out the value you read:

Serial.print("  |  ");

//delay(500);

return voltt;
 

}

float getpH()

{

 for(int i=0;i<10;i  )       //Get 10 sample value from the sensor for smooth the value

{ 

    buf[i]=analogRead(SensorPin);

    //delay(10);
}

for(int i=0;i<9;i  )        //sort the analog from small to large
{
        for(int j=i 1;j<10;j  )
    {
            if(buf[i]>buf[j])
            {
                temp=buf[i];
                buf[i]=buf[j];
                buf[j]=temp;
            }
    }
}
avgValue=0;
for(int i=2;i<8;i  )                      //take the average value of 6 center sample
        avgValue =buf[i];
float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
phValue=3.5*phValue;                      //convert the millivolt into pH value
Serial.print("pH:");  
Serial.print(phValue,2);
Serial.println(" ");
digitalWrite(13, HIGH);       
//delay(800);
digitalWrite(13, LOW);
return phValue;
 

}

недействительная команда отправки(строковая команда, int maxTime, char readReplay[])

{

 Serial.print(countTrueCommand);

Serial.print(". at command => ");

Serial.print(command);

Serial.print(" ");

while(countTimeCommand < (maxTime*1))

{

        esp8266.println(command);//at cipsend

        if(esp8266.find(readReplay))//ok

        {

            found = true;

            break;
        }

        countTimeCommand  ;
}
if(found == true)
{
        Serial.println("OYI");
        countTrueCommand  ;
        countTimeCommand = 0;
}
if(found == false)
{
        Serial.println("Fail");
        countTrueCommand = 0;
        countTimeCommand = 0;
}
found = false;
 

}

Комментарии:

1. Вам нужно отформатировать это намного лучше.