#include <SoulissFramework.h>/**************************************************************************ARDUINO MEGADynamic AddressingRS485 Input***************************************************************************/// Let the IDE point to the Souliss framework#include "SoulissFramework.h"//Debug#define SERIALPORT_INSKETCH#define LOG Serial//#define SOULISS_DEBUG_INSKETCH//#define SOULISS_DEBUG 0//#define VNET_DEBUG_INSKETCH//#define VNET_DEBUG 1//#define MaCaco_DEBUG_INSKETCH//#define MaCaco_DEBUG 1#include <bconf/StandardArduino.h> // Use a standard Arduino#include "conf/ethW5100.h" // Ethernet through Wiznet W5100#include "conf/DynamicAddressing.h" // Use dynamic address//Not a bridge//#include "conf/SuperNode.h" // The main node is the SuperNode// Include framework code and libraries#include <SPI.h>#include <EEPROM.h>/*** All configuration includes should be above this line ***/#include "Souliss.h"#include "util_local.h"#include "util.h"// This is the memory slot used for the execution of the logic#define TEMPERATURE_SLOT 0 //Temperature uses 2 slots#define LIGHT1 2#define LIGHT2 3#define LIGHT3 4#define LIGHT4 5#define LIGHT5 6#define LIGHT6 7#define LIGHT7 8#define LIGHT8 9#define DIMMER1_CONTROL 10#define DIMMER1_INTENSITY 11// Pinouts#define RELAY1 A0#define RELAY2 A1#define RELAY3 A2#define RELAY4 A3#define RELAY5 A4#define RELAY6 A5#define RELAY7 A6#define RELAY8 A7#define DIMMER1_PIN 9#define TEMP_1WIRE 13#define RS485_DE A9#define RS485_RE_NEG A8#define RS485_SERIAL Serial1#define RS485_BAUD 9600//Temperature#include <OneWire.h>#include <DallasTemperature.h>OneWire oneWire(TEMP_1WIRE); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.boolean hasSensor;//RS485 ModBus#include <ModbusMaster.h>ModbusMaster node;U8 RS485InPinStatus[16];void setup() {SetLED();serialInit();display_srcfile_details(PSTR(__FILE__));Serial.println("Iniciando...");Serial.print("Init Souliss...");Initialize();Serial.println("OK");// Set the status LED and let it blink for a couple of secondsTurnOnLED();// Set the inputsSerial.print("Init I/O...");initLowOnRealy(RELAY1);initLowOnRealy(RELAY2);initLowOnRealy(RELAY3);initLowOnRealy(RELAY4);initLowOnRealy(RELAY5);initLowOnRealy(RELAY6);initLowOnRealy(RELAY7);initLowOnRealy(RELAY8);pinMode(DIMMER1_PIN, OUTPUT);Serial.println("OK");// Define Simple Light logics for the relaysSerial.print("Set up lights...");Set_SimpleLight(LIGHT1);Set_SimpleLight(LIGHT2);Set_SimpleLight(LIGHT3);Set_SimpleLight(LIGHT4);Set_SimpleLight(LIGHT5);Set_SimpleLight(LIGHT6);Set_SimpleLight(LIGHT7);Set_SimpleLight(LIGHT8);Set_DimmableLight(DIMMER1_CONTROL);Serial.println("OK");// Setup the network configuration dynamic from gatewaySerial.print("Init dynamic addressing...");SetDynamicAddressing();Serial.println("OK");Serial.print("GetAddress...");GetAddress_Timeout(120000);Serial.println("OK");logAddresses();Serial.print("Init temperature...");// IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurementSet_Temperature(TEMPERATURE_SLOT); // Start up the librarysensors.begin();sensors.requestTemperatures();Serial.println("OK");Serial.print("Sensor count:");Serial.println(sensors.getDeviceCount());hasSensor = sensors.getDeviceCount() > 0;RS485Init();Serial.println("Initialization finished");}unsigned long start=0;void loop(){// Here we start to playEXECUTEFAST() {UPDATEFAST();FAST_50ms() { // We process the logic and relevant input and output every 50 milliseconds//Read from RS485 input boxuint8_t result;// Read 16 registers starting at 0)result = node.readDiscreteInputs(0, 16);if (result == node.ku8MBSuccess) {uint16_t response=node.getResponseBuffer(0);//for (j=0;j<16;j++){for (short j=0;j<8;j++){RS485ProcessInput(j, response & (1<<j), Souliss_T1n_ToggleCmd, LIGHT1+j);}//8//RS485ProcessInput(7, response & (1<<7), Souliss_T1n_ToggleCmd, DIMMER1_CONTROL);}// Execute the logic for RelaysLogic_SimpleLight(LIGHT1);Logic_SimpleLight(LIGHT2);Logic_SimpleLight(LIGHT3);Logic_SimpleLight(LIGHT4);Logic_SimpleLight(LIGHT5);Logic_SimpleLight(LIGHT6);Logic_SimpleLight(LIGHT7);Logic_SimpleLight(LIGHT8);// Drive the Relays - These are inverted low is onLowDigOut(RELAY1, Souliss_T1n_Coil, LIGHT1);LowDigOut(RELAY2, Souliss_T1n_Coil, LIGHT2);LowDigOut(RELAY3, Souliss_T1n_Coil, LIGHT3);LowDigOut(RELAY4, Souliss_T1n_Coil, LIGHT4);LowDigOut(RELAY5, Souliss_T1n_Coil, LIGHT5);LowDigOut(RELAY6, Souliss_T1n_Coil, LIGHT6);LowDigOut(RELAY7, Souliss_T1n_Coil, LIGHT7);LowDigOut(RELAY8, Souliss_T1n_Coil, LIGHT8);// Execute the logic that handle dimmableLogic_DimmableLight(DIMMER1_CONTROL);//Send the dimmable ouputanalogWrite(DIMMER1_PIN, mOutput(DIMMER1_INTENSITY));}// Here we process all communication with other nodesFAST_PeerComms();}EXECUTESLOW() {UPDATESLOW();SLOW_10s() {// Process the timer every 10 secondsTimer_SimpleLight(LIGHT1);Timer_SimpleLight(LIGHT2);Timer_SimpleLight(LIGHT3);Timer_SimpleLight(LIGHT4);Timer_SimpleLight(LIGHT5);Timer_SimpleLight(LIGHT6);Timer_SimpleLight(LIGHT7);Timer_SimpleLight(LIGHT8);// The timer handle timed-on statesTimer_DimmableLight(DIMMER1_CONTROL);if (hasSensor) {float temperature;sensors.requestTemperatures(); // Request temperaturestemperature = sensors.getTempCByIndex(0); // Read value and convert it to "simple-precision" or "double-precision"Souliss_ImportAnalog(memory_map, TEMPERATURE_SLOT, &temperature);Logic_Temperature(TEMPERATURE_SLOT);}// Once the join has been completed, turn the LED solid onif (!JoinInProgress()) {TurnOnLED();}}// Here we periodically check for a gateway to joinSLOW_PeerJoin();SLOW_15m () {if (JoinInProgress()) {Serial.print("GetAddress...");GetAddress_Timeout(3000);Serial.println("OK");logAddresses();}}}}/** Sets the relay pin as output for a low enabled relay. It will make sure it defaults to HIGH*/void initLowOnRealy(U8 pin){digitalWrite(pin,HIGH); // Low enabled realy, avoid it relay to start connectedpinMode(pin, OUTPUT);}/** Initializes the RS485 communication with the external device and the variables to process the read*/void RS485Init() {Serial.print("Init RS485 input...");pinMode(RS485_RE_NEG, OUTPUT);pinMode(RS485_DE, OUTPUT);RS485ReceiveMode();RS485_SERIAL.begin(RS485_BAUD);// Modbus slave ID 1node.begin(1, RS485_SERIAL);// Callbacks allow us to configure the RS485 transceiver correctlynode.preTransmission(RS485SendMode);node.postTransmission(RS485ReceiveMode);for(U8 i=0; i<16; i++){RS485InPinStatus[i] = PINRESET;}Serial.println("OK");}/** Read the input from the external RS485 device and writes to the memory map*/inline U8 RS485ProcessInput(U8 pin, U8 pin_value, U8 value, U8 slot) {if (pin_value) {if (RS485InPinStatus[pin] == PINRESET) {RS485InPinStatus[pin] = PINSET;memory_map[MaCaco_IN_s + slot] = value;return value;}} else {RS485InPinStatus[pin] = PINRESET;}return MaCaco_NODATACHANGED;}void RS485SendMode() {digitalWrite(RS485_RE_NEG, 1);digitalWrite(RS485_DE, 1);}void RS485ReceiveMode() {digitalWrite(RS485_RE_NEG, 0);digitalWrite(RS485_DE, 0);}
When SoulissApp send a command, it goes in Synch waiting for a state change. Likely your node is not notifying a state change properly.
As first try, scroll down in SoulissApp inside the node and see if the status goes from synch to online properly.
Dario.
--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+unsubscribe@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/souliss/a57f6ef4-82e2-4139-8825-1f94211ce843%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I've done some tests and it seems to work fine scrolling down from the node page. The offline seems randomly happen after an operation when it syncs, ie: turning on a light or changing the dinner value.
It happens more often (almost all the times) when changing the dinner value, and it would return back to the original value.
If it happens turning on a light it won't display the on state of the light although it has correctly been turned on.
What can I do to find the issue?
Thanks