Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 25
61  Topics / Home Automation and Networked Objects / Re: deleting values on: February 24, 2014, 09:26:09 am
What you described was typically what happens when you run out of memory. Any serious Arduino project always need to understand the memory footprint (SRAM, PROGMEM, EEMEM). The new IDE (1.5.5 beta) will report the memory usage. There are also a few utility functions available in AVR. Just do a search and you will find them.

That was the first take on this subject. If you get the memory footprint and it is too high what to do about that?

The first thing is to understand that many variables (in SRAM) are actually constants and can be moved into program memory. This makes more SRAM available but will require more program memory. More advanced is to understand how to transform global data structures to temporary on the stack.

You are using a lot of strings. Move them to program memory.
You have a constant vector of integer. Move them...

Now moving data to program memory is easy. The hard problem is access it as you cannot rely on the compiler to help with access code. You have to write it yourself. Again just do a search and you will find how to do this.

I see that you are using two Arduino libraries that produce memory issues; String and Ethernet. String uses the heap and Ethernet TCP/IP socket will force you to construct the whole message before sending. There are better libraries and solutions. Search and...

Cheers!
62  Topics / Home Automation and Networked Objects / Re: deleting values on: February 23, 2014, 03:28:15 pm
How much memory SRAM is used?

Cheers!
63  Topics / Home Automation and Networked Objects / Cosa SNMP agent library on: February 23, 2014, 03:24:35 pm
The second increment of the SNMP agent support is completed. The example sketch demonstrates SNMP MIB-2 handling (system attributes) and example Arduino MIB with digital pin, analog pin and power supply voltage read.

An OID match function (SNMP::OID::match) has been introduced to make it easy to compare request PDU OIDs and dispatch GET/SET response code. Below is a snippet from the updated CosaSNMP.ino example sketch; https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaSNMP/CosaSNMP.ino
Code:
bool system_mib(SNMP::PDU& pdu)
{
  // Match with SNMP MIB-2 System OID root
  int sys = pdu.oid.match(SNMP::MIB2_SYSTEM);
  if (sys < SNMP::sysDescr || sys > SNMP::sysServices) return (false);

  // Get system value
  if (pdu.type == SNMP::PDU_GET) {
    switch (sys) {
    case SNMP::sysDescr:
      ...
      break;
    ...
    }
  }

  // Set system value
  else if (pdu.type == SNMP::PDU_SET) {
    switch (sys) {
    case SNMP::sysContact:
      ...
      break;
    default:
      pdu.error_status = SNMP::READ_ONLY;
    }
  }
  return (true);
}
The example root OIDs (SNMP::MIB2_SYSTEM and SNMP::ARDUINO_MIB) are defined in program memory to reduce SRAM usage. Below are the definitions in SNMP.hh. Note that the root OID is a length prefixed sequnce of bytes and the access object is defined as a symbol in an enum to allows simple switch-case dispatch as above.
Code:
class SNMP {
public:
  ...
  // SNMP MIB-2 System OID(1.3.6.1.2.1.1)
  const static uint8_t MIB2_SYSTEM[] PROGMEM;
  enum {
    sysDescr = 1, // DisplayString(0..255), read-only, mandatory
    sysObjectID = 2, // OID, read-only, mandatory
    sysUpTime = 3, // TimeTicks, read-only, mandatory
    sysContact = 4, // DisplayString(0..255), read-write, mandatory
    sysName = 5, // DisplayString(0..255), read-write, mandatory
    sysLocation = 6, // DisplayString(0..255), read-write, mandatory
    sysServices = 7 // Integer(0..127), read-only, mandatory
  } __attribute__((packet));

  // Arduino MIB OID(1.3.6.1.4.1.36582)
  const static uint8_t ARDUINO_MIB[] PROGMEM;
  enum {
    ardDigitalPin = 1, // DigitalPin[0..22](0..1), read-write
    ardAnalogPin = 2, // AnalogPin[0..7](0..1023), read-only
    ardVcc = 3,         // Power supply[n](0..VCC), mV, read-only
  } __attribute__((packet));
  ...
};
Some examples of access with snmpget and snmpwalk. The options and parameters are (left-to-right); debug mode, version(1), community string(public), device network address and object identity(OID).
Code:
# Get value of digital pin 8
snmpget -d -v 1 -c public 192.168.0.22 0.1.3.6.1.4.1.36582.1.8
# Get value of analog pin 4
snmpget -d -v 1 -c public 192.168.0.22 0.1.3.6.1.4.1.36582.2.4
# Get power supply voltage (in milli-volt)
snmpget -d -v 1 -c public 192.168.0.22 0.1.3.6.1.4.1.36582.3.0
# Get system uptime
snmpget -d -v 1 -c public 192.168.0.22 0.1.3.6.1.2.1.1.3
The command snmpwalk (and snmpgetnext) can be used to iterate over the MIB and access all value; System MIB settings and status (uptime), and the Arduino Pins (Digital, Analog) and Power supply voltage. Below is a test run.
Code:
$ snmpwalk -v1 -c public 192.168.0.22 0
ccitt.1.3.6.1.2.1.1.1 = STRING: "<description>"
ccitt.1.3.6.1.2.1.1.2 = OID: ccitt.9.1.3.6.1.4.1.36582
ccitt.1.3.6.1.2.1.1.3 = 806
ccitt.1.3.6.1.2.1.1.4 = STRING: "<your name>"
ccitt.1.3.6.1.2.1.1.5 = STRING: "<device name>"
ccitt.1.3.6.1.2.1.1.6 = STRING: "<device location>"
ccitt.1.3.6.1.2.1.1.7 = INTEGER: 66
ccitt.1.3.6.1.4.1.36582.1.0 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.1 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.2 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.3 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.4 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.5 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.6 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.7 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.8 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.9 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.10 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.11 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.12 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.13 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.14 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.15 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.16 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.17 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.18 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.19 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.20 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.21 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.22 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.2.0 = INTEGER: 1023
ccitt.1.3.6.1.4.1.36582.2.1 = INTEGER: 1023
ccitt.1.3.6.1.4.1.36582.2.2 = INTEGER: 753
ccitt.1.3.6.1.4.1.36582.2.3 = INTEGER: 620
ccitt.1.3.6.1.4.1.36582.2.4 = INTEGER: 510
ccitt.1.3.6.1.4.1.36582.2.5 = INTEGER: 437
ccitt.1.3.6.1.4.1.36582.2.6 = INTEGER: 368
ccitt.1.3.6.1.4.1.36582.2.7 = INTEGER: 336
ccitt.1.3.6.1.4.1.36582.3.0 = INTEGER: 4673
End of MIB
Cheers!
64  Topics / Home Automation and Networked Objects / Cosa MQTT client library on: February 23, 2014, 03:22:46 pm
The second increment of the Cosa MQTT client class is now available. This update will handling incoming publish messages with higher quality of service and correctly respond with acknowledgement messages (PUBACK/PUBREC/PUBCOMP). A new MQTT::Client member function publish_P will allow topic values from program memory buffers.

The typical publish usage pattern is as below:
Code:
  // Start ethernet controller and request network address for hostname
  ethernet.begin_P(HOSTNAME));

  // Start MQTT client with socket and connect to server
  client.begin(ethernet.socket(Socket::TCP));
  client.connect(SERVER, CLIENT);

  // Publish data
  client.publish(TOPIC, VALUE, sizeof(VALUE));
  client.disconnect();
The subscribe and service of incoming publish request usage pattern is:
Code:
class MQTTClient : public MQTT::Client {
public:
  virtual void on_publish(char* topic, void* buf, size_t count);
};

void
MQTTClient::on_publish(char* topic, void* buf, size_t count)
{
  // Handle incoming publish for topic/value
}

MQTTClient client;

void setup()
{
  // Start ethernet controller and request network address for hostname
  ethernet.begin_P(HOSTNAME);

  // Start MQTT client with socket and connect to server
  client.begin(ethernet.socket(Socket::TCP)));
  client.connect(SERVER, CLIENT);

  // Subscribe to a topic
  client.subscribe(TOPIC);
}

void loop()
{
  ...
  // Service incoming publish messages
  client.service());
  ...
}
Two new MQTT client example sketches are available.

1. CosaMQTTtemperature
Reads 1-wire temperature sensor (DS18B20) and publishes to MQTT server.
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/MQTT/CosaMQTTtemperature/CosaMQTTtemperature.ino

2. CosaMQTThumidity
Reads DHT11 humidity and temperature and publishes on two topics.
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/MQTT/CosaMQTThumidity/CosaMQTThumidity.ino

Cheers!
65  Using Arduino / Sensors / Re: connecting a distance measuring sensor and a cumpass to the arduino splora on: February 23, 2014, 03:10:32 pm
No you cannot connect those devices directly. The Esplora does not really support I2C. Could be done with a soft TWI implementation.

Cheers!
66  Using Arduino / Sensors / Re: Use SPI with LMP91200 on: February 23, 2014, 02:45:10 pm
There is no SPI address. Instead this transfer protocol uses a chip select pin. The device does not connect MISO. Simply connect SCK, MOSI and a chip select pin and you are ready to go.

Cheers!
67  Development / Other Software Development / Re: Libera for LCD menu Selection on: February 23, 2014, 02:35:18 pm
http://forum.arduino.cc/index.php?topic=178395.msg1322559#msg1322559

Cheers!
68  Development / Other Software Development / Re: Move SDA/SCL pins on the Arduino Leonardo/micro with custom firmware ? on: February 23, 2014, 02:23:13 pm
Is it possible for me to compile a custom bootloader that will reassign sda and scl pins to analog ones (as I do not use them at all) like on the uno/nano ? I thought that "just" reassign pin in pins_arduino.h could be enough. Is that right ?

Or does the micro need to use interrupt to drive the i2c ? If so, do I have any other option to have i2c, hardware uart and 2 interrupt pins free (appart from keeping the nano and use an external i2c to uart bridge, which I have already considered) ?
No, you cannot compile a custom bootloader that reassigns sda and scl pins. No you cannot "just" change pins_arduino.h. This is why it is called hardware.

No, interrupts are not used with I2C, sda and scl.

Can it be solved another way? Yes, [Alternative 1] use the UART (pin 0 and pin 1). Use the I2C (pin2 and pin3) and use pin change interrupts instead of external interrupts. [Alternative 2] use either soft UART to free pin 0 and pin1 as external interrupt pins or soft I2C to free pin 2 and pin3.

BW: All the information is available in the references you posted.

Cheers!
69  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: February 21, 2014, 03:04:26 pm
A short update on the latest development. Two new MQTT client example sketches are available together with the the very first increments of the multi-tasking support.

The two MQTT example sketches show how easy it is to measure and push sensor data to an MQTT server. With available apps and web-clients no extra efford is needed to start monitoring.

1. CosaMQTTtemperature
Reads 1-wire temperature sensor (DS18B20) and publishes to MQTT server.
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/IoT/MQTT/CosaMQTTtemperature/CosaMQTTtemperature.ino

2. CosaMQTThumidity
Reads DHT11 humidity and temperature and publishes on two topics.
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/IoT/MQTT/CosaMQTThumidity/CosaMQTThumidity.ino

3. Cosa/Nucleo/Thread+Semaphore+Mutex
The first increments towards threads and other RTOS functionality contains a minimalistic implementation of threads (coroutines), semaphores and mutex. No assembly code, only C/C++ and a very small foot-print. The context switch (resume) is only four lines of code and together with the main thread run() member function supports low power idle mode.
Code:
void Thread::resume(Thread* t)
{
  if (setjmp(m_context)) return;
  s_running = t;
  if (t->m_state) s_go_idle = false;
  longjmp(t->m_context, 1);
}
// Main thread with low power mode support
void Thread::run()
{
  while (1) {
    s_go_idle = true;
    yield();
    if (s_go_idle) Power::sleep(s_mode);
  }
}
Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Nucleo/Thread.hh
Source: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Nucleo/Thread.cpp
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/Nucleo/CosaNucleoThread/CosaNucleoThread.ino
And semaphores;
Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Nucleo/Semaphore.hh
Source: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Nucleo/Semaphore.cpp
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/Nucleo/CosaNucleoSemaphore/CosaNucleoSemaphore.ino
And mutex (some syntactic sugar for mutual exclusive blocks of code using semaphores)
Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Nucleo/Mutex.hh
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/Nucleo/CosaNucleoMutex/CosaNucleoMutex.ino
There is also a start of a benchmark suite. The initial context switch benchmark shows 12 us and semaphore signal-wait at 42 us.
https://github.com/mikaelpatel/Cosa/blob/master/examples/Nucleo/CosaNucleoBenchmarks/CosaNucleoBenchmarks.ino
This is without any optimizations. All written in standard C/C++. There are additional example sketches, https://github.com/mikaelpatel/Cosa/tree/master/examples/Nucleo, such as the classical blink sketch with two threads; one for the LED blink and the other controlling the blink period. They may be built and run on standard Arduino, Mega, Mighty and Tiny. The blink thread sketch will run three threads (main, LED and LED controller) on as little as ATtiny85's SRAM size (512 byte) and less than 2K byte program memory. https://github.com/mikaelpatel/Cosa/blob/master/examples/Nucleo/CosaNucleoBlink/CosaNucleoBlink.ino
The main thread will power down while waiting for the Watchdog interrupt giving less than 5 uA when LED is off and typically 1-3 mA when LED is on.

Cheers!
70  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: February 18, 2014, 05:21:19 pm
The second increment of the Cosa MQTT client class is now available. This update will handling incoming publish messages with higher quality of service and correctly respond with acknowledgement messages (PUBACK/PUBREC/PUBCOMP). A new MQTT::Client member function publish_P will allow topic values from program memory buffers.

The typical publish usage pattern is as below:
Code:
 // Start ethernet controller and request network address for hostname
  ethernet.begin_P(HOSTNAME));

  // Start MQTT client with socket and connect to server
  client.begin(ethernet.socket(Socket::TCP));
  client.connect(SERVER, CLIENT);

  // Publish data
  client.publish(TOPIC, VALUE, sizeof(VALUE));
  client.disconnect();
The subscribe and service of incoming publish request usage pattern is:
Code:
class MQTTClient : public MQTT::Client {
public:
  virtual void on_publish(char* topic, void* buf, size_t count);
};

void
MQTTClient::on_publish(char* topic, void* buf, size_t count)
{
  // Handle incoming publish for topic/value
}

MQTTClient client;

void setup()
{
  // Start ethernet controller and request network address for hostname
  ethernet.begin_P(HOSTNAME);

  // Start MQTT client with socket and connect to server
  client.begin(ethernet.socket(Socket::TCP)));
  client.connect(SERVER, CLIENT);

  // Subscribe to a topic
  client.subscribe(TOPIC);
}

void loop()
{
  ...
  // Service incoming publish messages
  client.service());
  ...
}
For further details see links in previous post on MQTT client.

Cheers!
71  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: February 17, 2014, 06:29:04 pm
A first increment of a MQTT (V3.1) client class is now available in the Cosa library.

Example sketch: https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaMQTT/CosaMQTT.ino
Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/INET/MQTT.hh
Documentation: http://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/d5/db8/classMQTT.html
http://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/dc/df4/classMQTT_1_1Client.html

Use the MQTT web-service (http://mqtt.io/) for simple testing. On the web-page; subcribe to topic "public/cosa/a/#" and publish to topic "public/cosa/a/d". The example sketch will publish using all three quality of service levels. And service publish requests from the server. Please note that the client only handles incoming "fire and forget" (QoS level 0) publish in this version.

Cheers!
72  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: February 16, 2014, 07:12:09 pm
The __PROGMEM is a work-around to remove compiler warnings when using PROGMEM in the current version of GCC/AVR included in Arduino 1.0.5 and 1.5.5 BETA. In Cosa program memory data structures (and strings) are used when possible to make as much SRAM available to applications as possible.

The symbol __PROGMEM is defined in Cosa/Types.h and recently adjusted to work for compiling without using the Arduino IDE. With the new compiler __PROGMEM should simply be defined as PROGMEM (See Cosa/Types.h).

Please use the github issues list and I will consider adding support for this compiler version. A simple compiler version check will do the trick (in Cosa/Types.h).

Cheers!

PS: PSTR() needs to also be fixed to reduce the amount of duplicates. This might also been fixed in the new compiler version? DS.
73  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: February 10, 2014, 03:33:10 pm
A new Cosa support class for Webserver design has been added. The new class HTTP::Server will handle the overall interaction pattern (socket listen, accept connection, scan command line with URL, flush generated HTTP page and disconnect client connection). Applications should sub-class the HTTP::Server and implement the response member function on_request(). Below is a snippet from the refactored CosaWebServer example sketch: https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaWebServer/CosaWebServer.ino
Code:
#include "Cosa/INET/HTTP.hh"

// Example WebServer that responds with HTTP page with state of pins
class WebServer : public HTTP::Server {
public:
  ...
  // Response member function
  virtual void on_request(char* url);
  ...
};

void WebServer::on_request(char* url)
{
 
  // Bind the socket to an iostream
  IOStream page(m_sock);
  ...
  // Reply page; header and footer are static, contents dynamic
  static const char header[] PROGMEM = ...
  static const char footer[] PROGMEM = ...
  static const char BR[] PROGMEM = ...
  ...
  // Construct the page; header-contents-footer
  page << header;
  for (uint8_t i = 0; i < 14; i++)
    page << PSTR("D") << i << PSTR(": ") << InputPin::read(i) << BR;
  for (uint8_t i = 0; i < 4; i++)
    page << PSTR("A") << i << PSTR(": ") << AnalogPin::sample(i) << BR;
  page << PSTR("Vcc (mV): ") << AnalogPin::bandgap() << BR;
  page << PSTR("Memory (byte): ") << free_memory() << BR;
  ...
  page << footer;
}
...
// W5100 Ethernet Controller and WebServer
W5100 ethernet(mac);
WebServer server;

void setup()
{
  ...
  // Initiate ethernet controller with address
  uint8_t ip[4] = { IP };
  uint8_t subnet[4] = { SUBNET };
  ASSERT(ethernet.begin(ip, subnet));
  // Start the server
  ASSERT(server.begin(ethernet.socket(Socket::TCP, PORT)));
}

void loop()
{
  // Service incoming requests
  server.request();
}
The Cosa W5100 device driver allows streaming of data directly to the internal transmission buffers on the W5100 and does not require any message buffers on the Arduino. It is not limited to the available SRAM. Instead any size of response page is possible (from program memory or SD file).

Cheers!
74  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: February 09, 2014, 04:41:37 pm
The third and final increment of the SNMP agent support is now available; An abstract class SNMP::MIB is introduced to help structure the SNMP request handling. An implementation is available for the mandatory MIB-2 System entries (see https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/INET/SNMP.hh#L157). A MIB handler implementation is also available to demonstrate a simple Arduino MIB with entries for digital and analog pin and power supply voltage reading. Below is a snippet from the example sketch (CosaSNMP).
Code:
...
W5100 ethernet(mac);
SNMP snmp;
SNMP::MIB2_SYSTEM mib2(descr, contact, name, location);
ARDUINO_MIB arduino;

void setup()
{
  ...
  // Start ethernet controller and request network address for hostname
  ASSERT(ethernet.begin(hostname));
  ...
  // Start the SNMP manager with a connection-less socket
  ASSERT(snmp.begin(ethernet.socket(Socket::UDP, SNMP::PORT), &mib2, &arduino));
}

void loop()
{
  // Service SNMP requests with given MIB handlers (mib2, arduino)
  SNMP::PDU pdu;
  if (snmp.request(pdu) < 0) return;
  // Print available memory and resulting protocol data unit
  TRACE(free_memory());
  trace << pdu << endl;
}
The SNMP class member function request() will handle the receiving of requests, dispatch to the attached MIB handlers, and sending of the responses (PDU).  The example Arduino MIB handler has the following interface:
Code:
/**
 * Arduino MIB OID(1.3.6.1.4.1.36582)
 */
class ARDUINO_MIB : public SNMP::MIB {
private:
  enum {
    ardDigitalPin = 1,      // Digital pin[0..22](0..1), read-only
    ardAnalogPin = 2,      // Analog pin[0..7](0..1023), read-only
    ardVcc = 3,      // Power supply[0](0..VCC), mV, read-only
  } __attribute__((packet));

public:
  /**
   * @override SNMP::MIB
   * Return object identity root for Arduino MIB.
   */
  virtual const uint8_t* get_oid()
  {
    return (SNMP::ARDUINO_MIB_OID);
  }
    
  /**
   * @override SNMP::MIB
   * Handle Arduino MIB objects SNMP requests. Returns true and
   * value for SNMP::GET in given protocol data unit, otherwise false.
   * @param[in,out] pdu protocol data unit.
   * @return bool
   */
  virtual bool is_request(SNMP::PDU& pdu);
};
Please see the example sketch for the full implementation; https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaSNMP/CosaSNMP.ino

Cheers!
75  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: February 07, 2014, 07:39:36 pm
The second increment of the SNMP agent support is completed. The example sketch demonstrates SNMP MIB-2 handling (system attributes) and example Arduino MIB with digital pin, analog pin and power supply voltage read.

An OID match function (SNMP::OID::match) has been introduced to make it easy to compare request PDU OIDs and dispatch GET/SET response code. Below is a snippet from the updated CosaSNMP.ino example sketch; https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaSNMP/CosaSNMP.ino
Code:
bool system_mib(SNMP::PDU& pdu)
{
  // Match with SNMP MIB-2 System OID root
  int sys = pdu.oid.match(SNMP::MIB2_SYSTEM);
  if (sys < SNMP::sysDescr || sys > SNMP::sysServices) return (false);

  // Get system value
  if (pdu.type == SNMP::PDU_GET) {
    switch (sys) {
    case SNMP::sysDescr:
      ...
      break;
    ...
    }
  }

  // Set system value
  else if (pdu.type == SNMP::PDU_SET) {
    switch (sys) {
    case SNMP::sysContact:
      ...
      break;
    default:
      pdu.error_status = SNMP::READ_ONLY;
    }
  }
  return (true);
}
The example root OIDs (SNMP::MIB2_SYSTEM and SNMP::ARDUINO_MIB) are defined in program memory to reduce SRAM usage. Below are the definitions in SNMP.hh. Note that the root OID is a length prefixed sequnce of bytes and the access object is defined as a symbol in an enum to allows simple switch-case dispatch as above.
Code:
class SNMP {
public:
  ...
  // SNMP MIB-2 System OID(1.3.6.1.2.1.1)
  const static uint8_t MIB2_SYSTEM[] PROGMEM;
  enum {
    sysDescr = 1, // DisplayString(0..255), read-only, mandatory
    sysObjectID = 2, // OID, read-only, mandatory
    sysUpTime = 3, // TimeTicks, read-only, mandatory
    sysContact = 4, // DisplayString(0..255), read-write, mandatory
    sysName = 5, // DisplayString(0..255), read-write, mandatory
    sysLocation = 6, // DisplayString(0..255), read-write, mandatory
    sysServices = 7 // Integer(0..127), read-only, mandatory
  } __attribute__((packet));

  // Arduino MIB OID(1.3.6.1.4.1.36582)
  const static uint8_t ARDUINO_MIB[] PROGMEM;
  enum {
    ardDigitalPin = 1, // DigitalPin[0..22](0..1), read-write
    ardAnalogPin = 2, // AnalogPin[0..7](0..1023), read-only
    ardVcc = 3,        // Power supply[n](0..VCC), mV, read-only
  } __attribute__((packet));
  ...
};
Some examples of access with snmpget and snmpwalk. The options and parameters are (left-to-right); debug mode, version(1), community string(public), device network address and object identity(OID).
Code:
# Get value of digital pin 8
snmpget -d -v 1 -c public 192.168.0.22 0.1.3.6.1.4.1.36582.1.8
# Get value of analog pin 4
snmpget -d -v 1 -c public 192.168.0.22 0.1.3.6.1.4.1.36582.2.4
# Get power supply voltage (in milli-volt)
snmpget -d -v 1 -c public 192.168.0.22 0.1.3.6.1.4.1.36582.3.0
# Get system uptime
snmpget -d -v 1 -c public 192.168.0.22 0.1.3.6.1.2.1.1.3
The command snmpwalk (and snmpgetnext) can be used to iterate over the MIB and access all value; System MIB settings and status (uptime), and the Arduino Pins (Digital, Analog) and Power supply voltage. Below is a test run.
Code:
$ snmpwalk -v1 -c public 192.168.0.22 0
ccitt.1.3.6.1.2.1.1.1 = STRING: "<description>"
ccitt.1.3.6.1.2.1.1.2 = OID: ccitt.9.1.3.6.1.4.1.36582
ccitt.1.3.6.1.2.1.1.3 = 806
ccitt.1.3.6.1.2.1.1.4 = STRING: "<your name>"
ccitt.1.3.6.1.2.1.1.5 = STRING: "<device name>"
ccitt.1.3.6.1.2.1.1.6 = STRING: "<device location>"
ccitt.1.3.6.1.2.1.1.7 = INTEGER: 66
ccitt.1.3.6.1.4.1.36582.1.0 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.1 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.2 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.3 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.4 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.5 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.6 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.7 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.8 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.9 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.10 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.11 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.12 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.13 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.14 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.15 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.16 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.17 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.18 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.19 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.20 = INTEGER: 1
ccitt.1.3.6.1.4.1.36582.1.21 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.1.22 = INTEGER: 0
ccitt.1.3.6.1.4.1.36582.2.0 = INTEGER: 1023
ccitt.1.3.6.1.4.1.36582.2.1 = INTEGER: 1023
ccitt.1.3.6.1.4.1.36582.2.2 = INTEGER: 753
ccitt.1.3.6.1.4.1.36582.2.3 = INTEGER: 620
ccitt.1.3.6.1.4.1.36582.2.4 = INTEGER: 510
ccitt.1.3.6.1.4.1.36582.2.5 = INTEGER: 437
ccitt.1.3.6.1.4.1.36582.2.6 = INTEGER: 368
ccitt.1.3.6.1.4.1.36582.2.7 = INTEGER: 336
ccitt.1.3.6.1.4.1.36582.3.0 = INTEGER: 4673
End of MIB
Cheers!
Pages: 1 ... 3 4 [5] 6 7 ... 25