Hi,
I have setup a "simpleMosbus" network that works fine.
This controls an electric gate opener and a door bell.
slave id2 is controlling the gate motor.
Slave id3 picks up doorbell press and open close buttons
I now want to add ioT using the android Blynk app. www.blynk.cc
the app works on its own, the simpleModbus works on its own,
as soon as i enable Blynk (#include <BlynkSimpleEthernet.h> ) , comms over simpleModbus fails.
Master code.
#include <SimpleModbusMaster.h>
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h> // IF this is left in (allong with Blynk.run(); in loop), communication on simplemodbus fails////////////////////////////////////////////////
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; //Removed
SimpleTimer timer;
//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 150 // the scan rate //was 200 dropped to speed up update
#define retry_count 10
// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2
// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
PACKET1,
PACKET2,
PACKET3,
PACKET4,
// PACKET5,
// PACKET6,
TOTAL_NO_OF_PACKETS // leave this last entry
};
// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];
// The total amount of available memory on the master to store data
//////////////// registers of your master ///////////////////
enum
{
// just add or remove registers and your good to go...
// The first register starts at address 0
//DATA IN/OUT OF SLAVE ID2
GATE_CONTROL, //0 in from slave3 internal phone buttons
DOOR_BELL, //1 in from slave3 bell pressed?
GATE_CONTROL_MASTER, //2 send this to slave 2 to open/close/stop gate
SPAIR3, //3
SPAIR4, //4
GATE_STATUS, //5 in frome slave2
SPAIR6, //6
SPAIR7, //7
SPAIR8, //8
SPAIR9, //9
REGS_SIZE // leave this one
// total number of registers for function 3 and 16 share the same register array
// i.e. the same address space
};
// Masters register array
unsigned int regs[REGS_SIZE];
void setup()
{
//move data detween slaves
//slave id 1 = door phone
//slave id 2 = gate controller
//slave id 3 = internal phone buttons
// modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 5, 3, 0); // data read from the slave from first and next x many. put in last
// modbus_construct(&packets[PACKET2], 1, PRESET_MULTIPLE_REGISTERS, 1, 1, 1); // data to be written to the slave
modbus_construct(&packets[PACKET1], 2, READ_HOLDING_REGISTERS, 5, 1, 5); // 2= slavegate controler read reg5 for ONE reg , put it in my reg5 (first digit)
modbus_construct(&packets[PACKET2], 3, READ_HOLDING_REGISTERS, 5, 2, 0); // 3= slavegate controler read reg5 for two reg , put it in my reg0 (first digit)
modbus_construct(&packets[PACKET3], 2, PRESET_MULTIPLE_REGISTERS, 0, 1, 0); //put from masters reg0 for 1 reg put it in slave reg0
modbus_construct(&packets[PACKET4], 3, PRESET_MULTIPLE_REGISTERS, 0, 1, 5); //put from masters reg0 for 1 reg put it in slave reg5
// Initialize the Modbus Finite State Machine
modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth);
// Setup a function to be called every second
timer.setInterval(1000L, sendUptime);
}
void loop()
{
modbus_update();
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
// if ( Regs[GATE_CONTROL] == 1 && BUTTONb == LOW ){ }
}
void sendUptime()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, millis() / 1000);
}
slave_gate_opener3.ino (6.13 KB)
slave_internal_controler.ino (5.24 KB)
SimpleModbusMaster.cpp (15.3 KB)
SimpleModbusMaster.h (5.96 KB)