Ethernet Gateway: How to turn Off Debug?



  • Hi Guys,

    I´m trying to deactivate to debug to save memory, but where in the Mysensor.h code and how do I have to do it?

    /*
     The MySensors library adds a new layer on top of the RF24 library.
     It handles radio network routing, relaying and ids.
    
     Created by Henrik Ekblad <henrik.ekblad@gmail.com>
    	
     This program is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License
     version 2 as published by the Free Software Foundation.
    */
    
    #ifndef MySensor_h
    #define MySensor_h
    
    #include "Version.h"   // Auto generated by bot
    #include "MyConfig.h"
    #include "MyMessage.h"
    #include <stddef.h>
    #include <avr/eeprom.h>
    #include <avr/pgmspace.h>
    #include <avr/wdt.h>
    #include <stdarg.h>
    
    #ifdef __cplusplus
    #include <Arduino.h>
    #include <SPI.h>
    #include "utility/LowPower.h"
    #include "utility/RF24.h"
    #include "utility/RF24_config.h"
    #endif
    
    #ifdef DEBUG
    #define debug(x,...) debugPrint(x, ##__VA_ARGS__)
    #else
    #define debug(x,...)
    #endif
    
    #define BAUD_RATE 115200
    
    #define AUTO 0xFF // 0-254. Id 255 is reserved for auto initialization of nodeId.
    #define NODE_SENSOR_ID 0xFF // Node child id is always created for when a node
    
    // EEPROM start address for mysensors library data
    #define EEPROM_START 0
    // EEPROM location of node id
    #define EEPROM_NODE_ID_ADDRESS EEPROM_START
    // EEPROM location of parent id
    #define EEPROM_PARENT_NODE_ID_ADDRESS (EEPROM_START+1)
    // EEPROM location of distance to gateway
    #define EEPROM_DISTANCE_ADDRESS (EEPROM_PARENT_NODE_ID_ADDRESS+1)
    #define EEPROM_ROUTES_ADDRESS (EEPROM_DISTANCE_ADDRESS+1) // Where to start storing routing information in EEPROM. Will allocate 256 bytes.
    #define EEPROM_CONTROLLER_CONFIG_ADDRESS (EEPROM_ROUTES_ADDRESS+256) // Location of controller sent configuration (we allow one payload of config data from controller)
    #define EEPROM_FIRMWARE_TYPE_ADDRESS (EEPROM_CONTROLLER_CONFIG_ADDRESS+24)
    #define EEPROM_FIRMWARE_VERSION_ADDRESS (EEPROM_FIRMWARE_TYPE_ADDRESS+2)
    #define EEPROM_FIRMWARE_BLOCKS_ADDRESS (EEPROM_FIRMWARE_VERSION_ADDRESS+2)
    #define EEPROM_FIRMWARE_CRC_ADDRESS (EEPROM_FIRMWARE_BLOCKS_ADDRESS+2)
    #define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_FIRMWARE_CRC_ADDRESS+2) // First free address for sketch static configuration
    
    // This is the nodeId for sensor net gateway receiver sketch (where all sensors should send their data).
    #define GATEWAY_ADDRESS ((uint8_t)0)
    #define BROADCAST_ADDRESS ((uint8_t)0xFF)
    #define TO_ADDR(x) (BASE_RADIO_ID + x)
    
    #define WRITE_PIPE ((uint8_t)0)
    #define CURRENT_NODE_PIPE ((uint8_t)1)
    #define BROADCAST_PIPE ((uint8_t)2)
    
    // Search for a new parent node after this many transmission failures
    #define SEARCH_FAILURES  5
    
    struct NodeConfig
    {
    	uint8_t nodeId; // Current node id
    	uint8_t parentNodeId; // Where this node sends its messages
    	uint8_t distance; // This nodes distance to sensor net gateway (number of hops)
    };
    
    struct ControllerConfig {
    	uint8_t isMetric;
    };
    
    #ifdef __cplusplus
    class MySensor : public RF24
    {
      public:
    	/**
    	* Constructor
    	*
    	* Creates a new instance of Sensor class.
    	*
    	* @param _cepin The pin attached to RF24 Chip Enable on the RF module (default 9)
    	* @param _cspin The pin attached to RF24 Chip Select (default 10)
    	*/
    	MySensor(uint8_t _cepin=DEFAULT_CE_PIN, uint8_t _cspin=DEFAULT_CS_PIN);
    
    	/**
    	* Begin operation of the MySensors library
    	*
    	* Call this in setup(), before calling any other sensor net library methods.
    	* @param incomingMessageCallback Callback function for incoming messages from other nodes or controller and request responses. Default is NULL.
    	* @param nodeId The unique id (1-254) for this sensor. Default is AUTO(255) which means sensor tries to fetch an id from controller.
    	* @param repeaterMode Activate repeater mode. This node will forward messages to other nodes in the radio network. Make sure to call process() regularly. Default in false
    	* @param parentNodeId Use this to force node to always communicate with a certain parent node. Default is AUTO which means node automatically tries to find a parent.
    	* @param paLevel Radio PA Level for this sensor. Default RF24_PA_MAX
    	* @param channel Radio channel. Default is channel 76
    	* @param dataRate Radio transmission speed. Default RF24_1MBPS
    	*/
    
    	void begin(void (* msgCallback)(const MyMessage &)=NULL, uint8_t nodeId=AUTO, boolean repeaterMode=false, uint8_t parentNodeId=AUTO, rf24_pa_dbm_e paLevel=RF24_PA_LEVEL, uint8_t channel=RF24_CHANNEL, rf24_datarate_e dataRate=RF24_DATARATE);
    
    	/**
    	 * Return the nodes nodeId.
    	 */
    	uint8_t getNodeId();
    
    	/**
    	* Each node must present all attached sensors before any values can be handled correctly by the controller.
        * It is usually good to present all attached sensors after power-up in setup().
    	*
    	* @param sensorId Select a unique sensor id for this sensor. Choose a number between 0-254.
    	* @param sensorType The sensor type. See sensor typedef in MyMessage.h.
    	* @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack.
    	* @param description A textual description of the sensor.
    	*/
    	void present(uint8_t sensorId, uint8_t sensorType, const char *description="", bool ack=false);
    
    	/**
    	 * Sends sketch meta information to the gateway. Not mandatory but a nice thing to do.
    	 * @param name String containing a short Sketch name or NULL  if not applicable
    	 * @param version String containing a short Sketch version or NULL if not applicable
    	 * @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack.
    	 *
    	 */
    	void sendSketchInfo(const char *name, const char *version, bool ack=false);
    
    	/**
    	* Sends a message to gateway or one of the other nodes in the radio network
    	*
    	* @param msg Message to send
    	* @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack.
    	* @return true Returns true if message reached the first stop on its way to destination.
    	*/
    	bool send(MyMessage &msg, bool ack=false);
    
    	/**
    	 * Send this nodes battery level to gateway.
    	 * @param level Level between 0-100(%)
    	 * @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack.
    	 *
    	 */
    	void sendBatteryLevel(uint8_t level, bool ack=false);
    
    	/**
    	* Requests a value from gateway or some other sensor in the radio network.
    	* Make sure to add callback-method in begin-method to handle request responses.
    	*
    	* @param childSensorId  The unique child id for the different sensors connected to this Arduino. 0-254.
    	* @param variableType The variableType to fetch
    	* @param destination The nodeId of other node in radio network. Default is gateway
    	*/
    	void request(uint8_t childSensorId, uint8_t variableType, uint8_t destination=GATEWAY_ADDRESS);
    
    	/**
    	 * Requests time from controller. Answer will be delivered to callback.
    	 *
    	 * @param callback for time request. Incoming argument is seconds since 1970.
    	 */
    	void requestTime(void (* timeCallback)(unsigned long));
    
    
    	/**
    	 * Processes incoming messages to this node. If this is a relaying node it will
    	* Returns true if there is a message addressed for this node just was received.
    	* Use callback to handle incoming messages.
    	*/
    	boolean process();
    
    	/**
    	 * Returns the most recent node configuration received from controller
    	 */
    	ControllerConfig getConfig();
    
    	/**
    	 * Save a state (in local EEPROM). Good for actuators to "remember" state between
    	 * power cycles.
    	 *
    	 * You have 256 bytes to play with. Note that there is a limitation on the number
    	 * of writes the EEPROM can handle (~100 000 cycles).
    	 *
    	 * @param pos The position to store value in (0-255)
    	 * @param Value to store in position
    	 */
    	void saveState(uint8_t pos, uint8_t value);
    
    	/**
    	 * Load a state (from local EEPROM).
    	 *
    	 * @param pos The position to fetch value from  (0-255)
    	 * @return Value to store in position
    	 */
    	uint8_t loadState(uint8_t pos);
    
    	/**
    	* Returns the last received message
    	*/
    	MyMessage& getLastMessage(void);
    
    	/**
    	 * Sleep (PowerDownMode) the Arduino and radio. Wake up on timer.
    	 * @param ms Number of milliseconds to sleep.
    	 */
    	void sleep(unsigned long ms);
    
    	/**
    	 * Wait for a specified amount of time to pass.  Keeps process()ing.
    	 * This does not power-down the radio nor the Arduino.
    	 * Because this calls process() in a loop, it is a good way to wait
    	 * in your loop() on a repeater node or sensor that listens to messages.
    	 * @param ms Number of milliseconds to sleep.
    	 */
    	void wait(unsigned long ms);
    
    	/**
    	 * Sleep (PowerDownMode) the Arduino and radio. Wake up on timer or pin change.
    	 * See: http://arduino.cc/en/Reference/attachInterrupt for details on modes and which pin
    	 * is assigned to what interrupt. On Nano/Pro Mini: 0=Pin2, 1=Pin3
    	 * @param interrupt Interrupt that should trigger the wakeup
    	 * @param mode RISING, FALLING, CHANGE
    	 * @param ms Number of milliseconds to sleep or 0 to sleep forever
    	 * @return true if wake up was triggered by pin change and false means timer woke it up.
    	 */
    	bool sleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
    
    	/**
    	 * Sleep (PowerDownMode) the Arduino and radio. Wake up on timer or pin change for two separate interrupts.
    	 * See: http://arduino.cc/en/Reference/attachInterrupt for details on modes and which pin
    	 * is assigned to what interrupt. On Nano/Pro Mini: 0=Pin2, 1=Pin3
    	 * @param interrupt1 First interrupt that should trigger the wakeup
    	 * @param mode1 Mode for first interrupt (RISING, FALLING, CHANGE)
    	 * @param interrupt2 Second interrupt that should trigger the wakeup
    	 * @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
    	 * @param ms Number of milliseconds to sleep or 0 to sleep forever
    	 * @return Interrupt number wake up was triggered by pin change and negative if timer woke it up.
    	 */
    	int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0);
    
    
    
    
    #ifdef DEBUG
    	void debugPrint(const char *fmt, ... );
    	int freeRam();
    #endif
    
      protected:
    	NodeConfig nc; // Essential settings for node to work
    	ControllerConfig cc; // Configuration coming from controller
    	bool repeaterMode;
    	bool autoFindParent;
    	bool isGateway;
    	MyMessage msg;  // Buffer for incoming messages.
    	MyMessage ack;  // Buffer for ack messages.
    
    	void setupRepeaterMode();
    	void setupRadio(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate);
    	boolean sendRoute(MyMessage &message);
    	boolean sendWrite(uint8_t dest, MyMessage &message, bool broadcast=false);
    
      private:
    #ifdef DEBUG
    	char convBuf[MAX_PAYLOAD*2+1];
    #endif
    	uint8_t failedTransmissions;
    	uint8_t *childNodeTable; // In memory buffer for routing information to other nodes. also stored in EEPROM
        void (*timeCallback)(unsigned long); // Callback for requested time messages
        void (*msgCallback)(const MyMessage &); // Callback for incoming messages from other nodes and gateway.
    
        void requestNodeId();
    	void setupNode();
    	void findParentNode();
    	uint8_t crc8Message(MyMessage &message);
    	uint8_t getChildRoute(uint8_t childId);
    	void addChildRoute(uint8_t childId, uint8_t route);
    	void removeChildRoute(uint8_t childId);
    	void internalSleep(unsigned long ms);
    };
    #endif
    
    #endif
    

    Thx for your help!


  • Admin



  • Yes I've read that but it didn't work. I have to disable debug in mysensor.h to save memory and there I have a problem to disable it. I uncommented debug but then I couldn't compile.


  • Admin

    Master branch? Works fine here...

    What is the compile error?



  • First of all: which "debug" do I have to uncomment in mysensor.h? I think that's where I made a mistake.


  • Admin

    Just put // before "#define DEBUG" like the instruction says (in reverse)



  • yes, it sounds so easy, but I can´t find that #define DEBUG in Mysensor.h
    all I found is this:

    #ifdef DEBUG
    #define debug(x,...) debugPrint(x, ##__VA_ARGS__)
    #else
    #define debug(x,...)
    #endif
    

    I uncommented all of that, then I couldn´t compile anymore. So that´s actually my problem. I´m feeling very dumb right now because I don´t get it 😞



  • You are changing in the wrong file.
    The file you should change in is MyConfig.h.

    #ifndef MyConfig_h
    #define MyConfig_h
    
    /***
     * Configure Sensor Network
     */
    #define RF24_CHANNEL	   76             //RF channel for the sensor net, 0-127
    #define RF24_DATARATE 	   RF24_250KBPS   //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
    #define RF24_PA_LEVEL 	   RF24_PA_MAX    //Sensor PA Level == RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, RF24_PA_HIGH=-6dBM, and RF24_PA_MAX=0dBm
    #define RF24_PA_LEVEL_GW   RF24_PA_LOW  //Gateway PA Level, defaults to Sensor net PA Level.  Tune here if using an amplified nRF2401+ in your gateway.
    #define BASE_RADIO_ID 	   ((uint64_t)0xA8A8E1FC00LL) // This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network.
    
    // MySensors online examples defaults
    #define DEFAULT_CE_PIN 9
    #define DEFAULT_CS_PIN 10
    
    
    /***
     * Enable/Disable debug logging
     */
    #define DEBUG  
    
    #endif
    


  • mmh, I tried that before, which worked, but still was too less memory available. So I got back to http://www.mysensors.org/build/ethernet_gateway where it is described like this: "Note that the ENC28J60 mdoule uses much more memory than W5100. You probably have to disable DEBUG in MySensors.h to make it compile."
    I´m confused now ;(


  • Admin

    MyConfig.h is the correct file to edit. Anything else you've seen is probably just a typo.



  • Ok, so I edited MyConfig.h but now I get this message from Arduino IDE:

    Sketch uses 31,890 bytes (103%) of program storage space. Maximum is 30,720 bytes.
    Global variables use 1,564 bytes (76%) of dynamic memory, leaving 484 bytes for local variables. Maximum is 2,048 bytes.

    So it still doesn´t fit. Any idea how to save some storage space?


Log in to reply
 

Suggested Topics

48
Online

11.4k
Users

11.1k
Topics

112.7k
Posts