donadonadona
@donadonadona
IT Магистрант

Вопрос по Arduino (ошибок скетча)?

Ардуино Уно, SIM800L, DHT11, Ethernet shield- для отслеживания температуры и вне установленного предела для отправки SMS. У меня скетч не сработал, где ошибка?
64064a13d4134cf39b01e94ad5ff0670.png
-----------
Вот:

#include SoftwareSerial.h
#include String.h
#include EEPROM.h
#include Wire.h
#include SPI.h
#include Ethernet.h
#include dht.h

// pins definition
SoftwareSerial sim800l(7, 6); // actual RX, TX pins of SIM800l board
const int TestButton = 10; // internal pull-up activated, button is wired to GND, LOW when pressed
const int LEDPowerFailure = 9;
const int LEDTemperatureFailure = 4;
const int LEDLANFailure = 11;
const int LEDDiagnostics = 13; // internal LED for diagnostics
const int PowerSenseInput= A1; // from DC adapter via a voltage divider
const int DHT11Pin = 12; // DHT11 onewire pin

// failure definitions constants - bitwise
const int StateOk = 0;
const int StatePowerDownFailure = 1;
const int StateLANFailure = 2;
const int StateTemperatureFailure = 4;
const int StateTest = 8;

float TempSensorValue; // current temperature from sensor DHT11
float PowerSenseInputValue; // voltage after divider
int PingFailure = 0; // flag
int PingCountOk; // counter
int TestButtonState; // pressed LOW
int State = StateOk; // status of the net/temp/power/test

// User configurable variables (via source recompile and upload to Arduino board again)
// pinging
byte useDhcp = true;
byte useDns = true;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// these valus must be changed
IPAddress deviceIp(192, 168, 1, 100); // Only if useDhcp is false !!!
IPAddress gatewayIp(192, 168, 1, 1); // Only if useDhcp is false !!!
IPAddress dnsIp(192, 168, 1, 1); // Only if useDhcp is false !!!
IPAddress subnet(255, 255, 255, 0); // Only if useDhcp is false !!!
IPAddress serverIp(173, 230, 152, 173); // Only if useDns is false !!!
char serverName[] = "server1.tu-plovdiv.bg"; // Only if useDns is true !!!
// thresholds
const int TemperatureAlarmValue = 36; // over 36C - alarm
const int PingCountAlarmValue = 3; // over 3 lost packets - alarm
const float DCPowerAlarmValue = 0.5; // under 0.5 volts after voltage diveider - alarm
const float DCPowerVoltage = 9.0; // voltage of the power adaptor

EthernetClient Client; // Declare client object
dht DHT; // DHT object

void setup() // initialise ports/values
{
pinMode(TestButton, INPUT_PULLUP); // LOW when pressed
// LEDs - light on HIGH
pinMode(LEDPowerFailure, OUTPUT);
pinMode(LEDTemperatureFailure, OUTPUT);
pinMode(LEDLANFailure, OUTPUT);
pinMode(LEDDiagnostics, OUTPUT);
// initialise Serial and SIM800l
sim800l.begin(9600); // initialize SIM800l module at 9600 bps
Serial.begin(9600); // debug messages to serial monitor of Arduino IDE
delay(500); // wait for proper initialization of the SIM800l 500mS
}

void loop()
{
State = StateOk;

// check
TestButtonState = digitalRead(buttonPin); // if LOW - do diagnostic (Power failure simulation)
if (TestButtonState == LOW) { // test diagnostic SMS and PowerLow LED simulation
Serial.println("Diagnostics button pressed.");
State = State | StateTest;
}

// check temperature
int chk = DHT.read11(DHT11Pin);
if (chk == DHTLIB_OK) {
TempSensorValue = DHT.temperature;
if (TempSensorValue > TemperatureAlarmValue) {
State = State | StateTemperatureFailure;
Serial.print("Temperature overflow ");
Serial.println(TempSensorValue, 1);
}
}

// check power down state, read twice after 500ms to avoid brownouts
PowerSenseInputValue = analogRead(PowerSenseInput) * (DCPowerVoltage / 2.0) / 1024;
if (PowerSenseInputValue < DCPowerAlarmValue) {
delay(500); // wait for brownout 500mS
PowerSenseInputValue = analogRead(PowerSenseInput) * (DCPowerVoltage / 2.0) / 1024;
if (PowerSenseInputValue < DCPowerAlarmValue) {
State = State | StatePowerDownFailure;
Serial.println("Power down.");
}
}

// check ping state of the server
// ..
if (PingFailure) {
State = State | StatePowerDownFailure;
Serial.println("Ping failed - server is down.");
}

// process state

if (sim800l.available()){ // is SIM800l receive SMS or status - dump it back
Serial.write(sim800l.read());
}
}

void SendTextMessage()
{
Serial.println("Sending Text Message...");
//
sim800l.print("AT+CMGF=1\r"); // Set the shield to SMS mode
delay(100);
sim800l.print("AT+CMGS=\"+3591234567\"\r"); // put actual number here
delay(200);
//
sim800l.print("Failure is: ");
// ... by State...
sim800l.print("\r"); //the content of the message
delay(500);
sim800l.print((char)26); //the ASCII code of the ctrl+z is 26 (required ^Z at end of SMS)
delay(100);
sim800l.println();
Serial.println("Text Message Sent.");
delay(500);
}
  • Вопрос задан
  • 1299 просмотров
Пригласить эксперта
Ответы на вопрос 3
@GreyPhantom
АСУТП, КИПиА
Ethernet shield какой? тот что на W5100 использует пины 4, 10, помимо SPI (4- выбор SD- картты, 10- собственно Ethernet). У Вас ,как я вижу, 10-й пин назначен входом, из-за чего может не работать как сам шилд, так и то что еще использует этот вывод.
Ответ написан
Что именно не работает?
Ответ написан
donadonadona
@donadonadona Автор вопроса
IT Магистрант
При вводе программный код в Arduino IDE
и после проверки Compile
Программа показала ошибки
которые я не знаю, как чистить.
Вот:
Arduino: 1.6.11 (Windows 10), Board: "Arduino/Genuino Uno"

Build options changed, rebuilding all
ServerGuard_Dona_with_SIM800l:53: error: 'dht' does not name a type

dht DHT; // DHT object

^

C:\Users\admin\Desktop\ServerGuard_Dona_with_SIM800l\ServerGuard_Dona_with_SIM800l.ino: In function 'void loop()':

ServerGuard_Dona_with_SIM800l:74: error: 'buttonPin' was not declared in this scope

TestButtonState = digitalRead(buttonPin); // if LOW - do diagnostic (Power failure simulation)

^

ServerGuard_Dona_with_SIM800l:81: error: expected primary-expression before '.' token

int chk = DHT.read11(DHT11Pin);

^

ServerGuard_Dona_with_SIM800l:82: error: 'DHTLIB_OK' was not declared in this scope

if (chk == DHTLIB_OK) {

^

ServerGuard_Dona_with_SIM800l:83: error: expected primary-expression before '.' token

TempSensorValue = DHT.temperature;

^

Multiple libraries were found for "Ethernet.h"
Used: C:\Users\admin\Documents\Arduino\libraries\Ethernet
Not used: C:\Program Files (x86)\Arduino\libraries\Ethernet
exit status 1
'dht' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы