Hi, I'm want to build an Agent device that sends Temp to the MIB with snmp protocol via Ethernet.
and this device should be able to change IP address from web server...
I have build web server to changing IP address and gateway and IT WORKS.
for changing mode between SETUP and Agent I have used switch case and a push button.
but arduino doesn't send data to MIB...
when I put snmp code at first case it works(webserver doesn't work)
please help me, this is my code:
void loop()
{
val = digitalRead(inPin);
switch(val) {
case LOW:
EthernetServer server(80);
server.begin(); //starting the server
EthernetClient client = server.available();
if (client) {
TextFinder finder(client );
while (client.connected()) {
if (client.available()) {
if( finder.find("GET /") ) {
if (finder.findUntil("setup", "\n\r")){
if (finder.findUntil("SBM", "\n\r")){
byte SET = finder.getValue();
while(finder.findUntil("DT", "\n\r")){
int val = finder.getValue();
// if val from "DT" is between 1 and 6 the according value must be a MAC value.
if(val >= 1 && val <= 6) {
mac[val - 1] = finder.getValue();
}
// if val from "DT" is between 7 and 10 the according value must be a IP value.
if(val >= 7 && val <= 10) {
ip[val - 7] = finder.getValue();
}
// if val from "DT" is between 11 and 14 the according value must be a MASK value.
if(val >= 11 && val <= 14) {
subnet[val - 11] = finder.getValue();
}
// if val from "DT" is between 15 and 18 the according value must be a GW value.
if(val >= 15 && val <= 18) {
gateway[val - 15] = finder.getValue();
}
}
// Now that we got all the data, we can save it to EEPROM
//for (int i = 0 ; i < 6; i++){
//EEPROM.write(i + 1,mac[i]);
//}
for (int i = 0 ; i < 4; i++){
EEPROM.write(i + 7, ip[i]);
}
for (int i = 0 ; i < 4; i++){
EEPROM.write(i + 11, subnet[i]);
}
for (int i = 0 ; i < 4; i++){
EEPROM.write(i + 15, gateway[i]);
}
// set ID to the known bit, so when you reset the Arduino is will use the EEPROM values
EEPROM.write(0, 0x92);
// if al the data has been written to EEPROM we should reset the arduino
// for now you'll have to use the hardware reset button
}
// and from this point on, we can start building our setup page
// and show it in the client's browser.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
for (int i = 0; i < 4; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table0[i])));
client.print( buffer );
}
for (int i = 0; i < 3; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[i])));
client.print( buffer );
}
client.print(mac[0],HEX);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[3])));
client.print( buffer );
client.print(mac[1],HEX);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[4])));
client.print( buffer );
client.print(mac[2],HEX);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[5])));
client.print( buffer );
client.print(mac[3],HEX);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[6])));
client.print( buffer );
client.print(mac[4],HEX);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[7])));
client.print( buffer );
client.print(mac[5],HEX);
for (int i = 0; i < 4; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[i])));
client.print( buffer );
}
client.print(ip[0],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[4])));
client.print( buffer );
client.print(ip[1],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[5])));
client.print( buffer );
client.print(ip[2],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[6])));
client.print( buffer );
client.print(ip[3],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[0])));
client.print( buffer );
client.print(subnet[0],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[1])));
client.print( buffer );
client.print(subnet[1],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[2])));
client.print( buffer );
client.print(subnet[2],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[3])));
client.print( buffer );
client.print(subnet[3],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[0])));
client.print( buffer );
client.print(gateway[0],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[1])));
client.print( buffer );
client.print(gateway[1],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[2])));
client.print( buffer );
client.print(gateway[2],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[3])));
client.print( buffer );
client.print(gateway[3],DEC);
strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[4])));
client.print( buffer );
for (int i = 0; i < 7; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table5[i])));
client.print( buffer );
}
strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[5])));
client.print( buffer );
client.println();
client.println();
client.println("<tr><td><font color=\"red\" size=\"2\" face=\"Verdana\"> You can not change the MAC address</font></td></tr></table>
");
break;
}}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
break;
}
}
delay(1);
client.stop();
} break;
case HIGH:
SnmpAgent.begin();
SnmpAgent.listen();
if (millis() - lastMillis > 10000) {
Sensors.requestTemperatures(); // Send the command to get temperatures
dtostrf(Sensors.getTempCByIndex(0), 1, 1, temperature);
lastMillis = millis();
}
break;
} delay(1);
}