Добрый день всем! Столкнулся с очень странной, на мой взгляд, проблемой. Собираю с Arduino статистику по SNMP и работает WEB страничка с отображением температуры, но тут решил подключить ещё и LCD 1602 и тут меня всё ввело в ступор. Итак, если я заливаю обычный тестовый скейтч Код (Text): #include <LiquidCrystal.h> LiquidCrystal lcd(12, 10, 5, 4, 3, 2); void setup() { lcd.begin(16, 2); lcd.print("hello, world!"); } void loop() { lcd.setCursor(0, 1); lcd.print(millis()/1000); }; то всё прекрасно работает, но как только я добавляю эти строки в свой код, то работает только статическая часть из setup. Часть из loop не хочет работать, хотя Serial.println в это месте нормально отображает информацию на com-порт... Вот собственно скейч: Код (Text): #include <SPI.h> #include <Ethernet.h> #include <Streaming.h> #include <MemoryFree.h> #include <Agentuino.h> #include <LiquidCrystal.h> LiquidCrystal lcd(12, 10, 5, 4, 3, 2); byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; IPAddress ip(192, 168, 1, 177); IPAddress mask(255, 255, 255, 0); IPAddress gate(192, 168, 1, 1); EthernetServer server(80); char hostname[80] = "Arduino Test"; char sensor0[80] = "Sensor 0 = "; char sensor1[80] = "Sensor 1 = "; char sensor2[80] = "Sensor 2 = "; char sensor3[80] = "Sensor 3 = "; char sensor4[80] = "Sensor 4 = "; char sensor5[80] = "Sensor 5 = "; static int32_t temperatura=0; //static COUNTER temperatura=0; // which analog pin to connect //#define THERMISTORPIN A0 // resistance at 25 degrees C #define THERMISTORNOMINAL 10000 // temp. for nominal resistance (almost always 25 C) #define TEMPERATURENOMINAL 25 // how many samples to take and average, more takes longer // but is more 'smooth' #define NUMSAMPLES 5 // The beta coefficient of the thermistor (usually 3000-4000) #define BCOEFFICIENT 3950 // the value of the 'other' resistor #define SERIESRESISTOR 10000 int samples[NUMSAMPLES]; //-----------------------------SNMP start-------------------------- // RFC1213-MIB OIDs // .iso (.1) // .iso.org (.1.3) // .iso.org.dod (.1.3.6) // .iso.org.dod.internet (.1.3.6.1) // .iso.org.dod.internet.mgmt (.1.3.6.1.2) // .iso.org.dod.internet.mgmt.mib-2 (.1.3.6.1.2.1) // .iso.org.dod.internet.mgmt.mib-2.system (.1.3.6.1.2.1.1) // .iso.org.dod.internet.mgmt.mib-2.system.sysDescr (.1.3.6.1.2.1.1.1) static char sysDescr[] PROGMEM = "1.3.6.1.2.1.1.1.0"; // read-only (DisplayString) // .iso.org.dod.internet.mgmt.mib-2.system.sysObjectID (.1.3.6.1.2.1.1.2) static char sysObjectID[] PROGMEM = "1.3.6.1.2.1.1.2.0"; // read-only (ObjectIdentifier) // .iso.org.dod.internet.mgmt.mib-2.system.sysUpTime (.1.3.6.1.2.1.1.3) static char sysUpTime[] PROGMEM = "1.3.6.1.2.1.1.3.0"; // read-only (TimeTicks) // .iso.org.dod.internet.mgmt.mib-2.system.sysContact (.1.3.6.1.2.1.1.4) static char sysContact[] PROGMEM = "1.3.6.1.2.1.1.4.0"; // read-write (DisplayString) // .iso.org.dod.internet.mgmt.mib-2.system.sysName (.1.3.6.1.2.1.1.5) static char sysName[] PROGMEM = "1.3.6.1.2.1.1.5.0"; // read-write (DisplayString) // .iso.org.dod.internet.mgmt.mib-2.system.sysLocation (.1.3.6.1.2.1.1.6) static char sysLocation[] PROGMEM = "1.3.6.1.2.1.1.6.0"; // read-write (DisplayString) // .iso.org.dod.internet.mgmt.mib-2.system.sysServices (.1.3.6.1.2.1.1.7) static char sysServices[] PROGMEM = "1.3.6.1.2.1.1.7.0"; // read-only (Integer) // Arduino defined OIDs // .iso.org.dod.internet.private (.1.3.6.1.4) // .iso.org.dod.internet.private.enterprises (.1.3.6.1.4.1) // .iso.org.dod.internet.private.enterprises.arduino (.1.3.6.1.4.1.36582) // .iso.org.dod.internet.private.enterprises.arduino.value.valA0-A5 (.1.3.6.1.4.1.36582.3.1-6) static char valA0[] PROGMEM = "1.3.6.1.4.1.36582.3.1.0"; // read-only (Integer) static char valA1[] PROGMEM = "1.3.6.1.4.1.36582.3.2.0"; // read-only (Integer) // .iso.org.dod.internet.private.enterprises.arduino.value.valD0-D13 (.1.3.6.1.4.1.36582.3.7-20) static char valD0[] PROGMEM = "1.3.6.1.4.1.36582.3.7.0"; // read-only (Integer) static char valD1[] PROGMEM = "1.3.6.1.4.1.36582.3.8.0"; // read-only (Integer) static char locDescr[] = "Agentuino, a light-weight SNMP Agent."; static char locObjectID[] = "1.3.6.1.4.1.36582"; static uint32_t locUpTime = 0; static char locContact[60] = "Mihail Afanasyev"; static char locName[60] = "Agentuino Test"; static char locLocation[60] = "Fryazino, MO, Russia"; static int32_t locServices = 7; uint32_t prevMillis = millis(); char oid[SNMP_MAX_OID_LEN]; SNMP_API_STAT_CODES api_status; SNMP_ERR_CODES status; //----------------------------SNMP End----------------------------- //----------------------------getTemp Start------------------------ float getTemp (char analog_pin){ uint8_t i; float average; for (i=0; i< NUMSAMPLES; i++) { samples[i] = analogRead(analog_pin); delay(10); } average = 0; for (i=0; i< NUMSAMPLES; i++) { average += samples[i]; } average /= NUMSAMPLES; average = 1023 / average - 1; average = SERIESRESISTOR / average; float steinhart; steinhart = average / THERMISTORNOMINAL; // (R/Ro) steinhart = log(steinhart); // ln(R/Ro) steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro) steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) steinhart = 1.0 / steinhart; // Invert steinhart -= 273.15; // convert to C return steinhart; } //-------------------------getTemp End---------------------------- //----------------------------PDU Function start------------------ void pduReceived() { SNMP_PDU pdu; Serial.println("UDP Packet Received..."); api_status = Agentuino.requestPdu(&pdu); if ( pdu.type == SNMP_PDU_GET || pdu.type == SNMP_PDU_GET_NEXT || pdu.type == SNMP_PDU_SET && pdu.error == SNMP_ERR_NO_ERROR && api_status == SNMP_API_STAT_SUCCESS ) { pdu.OID.toString(oid); Serial.print("OID = "); Serial.println(oid); if ( pdu.type == SNMP_PDU_SET ) { status = SNMP_ERR_READ_ONLY; } else if ( strcmp_P(oid, sysDescr ) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locDescr); } else if ( strcmp_P(oid, sysUpTime ) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_TIME_TICKS, locUpTime); } else if ( strcmp_P(oid, sysName ) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locName); } else if ( strcmp_P(oid, sysContact ) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locContact); } else if ( strcmp_P(oid, sysLocation ) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locLocation); } else if ( strcmp_P(oid, sysServices) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_INT, locServices); } else if ( strcmp_P(oid, sysObjectID) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_OCTETS, locObjectID); temperatura = getTemp(A0)*100; } else if ( strcmp_P(oid, valA0) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_INT32, temperatura); } else if ( strcmp_P(oid, valA1) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_INT, analogRead(1)); } else if ( strcmp_P(oid, valD0) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_INT, digitalRead(0)); } else if ( strcmp_P(oid, valD1) == 0 ) { status = pdu.VALUE.encode(SNMP_SYNTAX_INT, digitalRead(1)); } else { status = SNMP_ERR_NO_SUCH_NAME; } pdu.type = SNMP_PDU_RESPONSE; pdu.error = status; Agentuino.responsePdu(&pdu); } Agentuino.freePdu(&pdu); } //----------------------------PDU Function end--------------------- //_______________________SETUP_________________________ void setup(void) { lcd.begin(16, 2); lcd.print("TEST OK"); // <------------Это на экран выводит Serial.begin(9600); while (!Serial); Ethernet.begin(mac, ip, mask, gate); //--------------- api_status = Agentuino.begin(); if ( api_status == SNMP_API_STAT_SUCCESS ) { Agentuino.onPduReceive(pduReceived); delay(10); Serial.println("SNMP Agent Initiated..."); return; } delay(10); Serial.println("SNMP Agent failed!"); //--------------- server.begin(); analogReference(EXTERNAL); } //______________________________END SETUP START LOOP___________ void loop(void) { EthernetClient client = server.available(); if (client) { boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); client.println("Refresh: 5"); client.println(); client.println("<!DOCTYPE HTML>"); client.println("<html>"); client.println("<title>"); client.println(hostname); client.println("</title>"); client.println (sensor0); client.println(getTemp(A0)); client.println ("C°"); client.println("</br>"); client.println (sensor1); client.println(getTemp(A1)); client.println ("C°"); client.println("</br>"); client.println("</html>"); break; } } } delay(1); client.stop(); temperatura = getTemp(A0)*100; Serial.println(temperatura); // <---------------Вот это выводит через ком порт //Serial.println(getTemp(A0)); lcd.clear(); lcd.setCursor(0, 1); lcd.println(temperatura); // <-----------------почему-то не печатает на экране LCD эту информацию. delay(1000); // //----------------------------- SNMP ----------------- Agentuino.listen(); if ( millis() - prevMillis > 1000 ) { prevMillis += 1000; locUpTime += 100; } //----------------------------- END SNMP-------------- }
Добрый день! Тоже заинтересован сделать SNMP на Arduino UNO, для связки его с Cacti. Поробывал загрузить ваш sketch и получаю ошибку: Arduino: 1.6.5 (Windows 7), Board: "Arduino Uno" In file included from C:\Users\mago\AppData\Roaming\Arduino15\packages\arduino\hardware\avr\1.6.7\cores\arduino/Arduino.h:28:0, from C:\Users\mago\AppData\Roaming\Arduino15\packages\arduino\hardware\avr\1.6.7\libraries\SPI/SPI.h:17, from first-sketch_apr06a.ino:1: first-sketch_apr06a:53: error: variable 'sysDescr' must be const in order to be put into read-only section by means of '__attribute__((progmem))' first-sketch_apr06a:55: error: variable 'sysObjectID' must be const in order to be put into read-only section by means of '__attribute__((progmem))' first-sketch_apr06a:57: error: variable 'sysUpTime' must be const in order to be put into read-only section by means of '__attribute__((progmem))' first-sketch_apr06a:59: error: variable 'sysContact' must be const in order to be put into read-only section by means of '__attribute__((progmem))' first-sketch_apr06a:61: error: variable 'sysName' must be const in order to be put into read-only section by means of '__attribute__((progmem))' first-sketch_apr06a:63: error: variable 'sysLocation' must be const in order to be put into read-only section by means of '__attribute__((progmem))' first-sketch_apr06a:65: error: variable 'sysServices' must be const in order to be put into read-only section by means of '__attribute__((progmem))' first-sketch_apr06a:72: error: variable 'valA0' must be const in order to be put into read-only section by means of '__attribute__((progmem))' first-sketch_apr06a:73: error: variable 'valA1' must be const in order to be put into read-only section by means of '__attribute__((progmem))' first-sketch_apr06a:76: error: variable 'valD0' must be const in order to be put into read-only section by means of '__attribute__((progmem))' first-sketch_apr06a:77: error: variable 'valD1' must be const in order to be put into read-only section by means of '__attribute__((progmem))' variable 'sysDescr' must be const in order to be put into read-only section by means of '__attribute__((progmem))' В чем может быть проблема?