berikut kodingnya untuk modbus IoT thinger
#include <ThingerEthernet.h>
#define USERNAME "*****"
#define DEVICE_ID "*****"
#define DEVICE_CREDENTIAL "********"
ThingerEthernet thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
#include <SimpleModbusMaster.h>
#include <avr/wdt.h>
#define baud 9600
#define timeout 3000
#define polling 300 // the scan rate ms
#define retry_count 100
// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2
// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 1
enum
{
PACKET1,//
TOTAL_NO_OF_PACKETS // leave this last entry
};
// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];
// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];
void setup() {
uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
Ethernet.begin(mac, IPAddress(192, 168, 201, 10));
modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 0, 1, 0);//
modbus_configure(&Serial2, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
thing["freq"] >> [](pson& out){
out =(float) regs [1]/100;
};
}
void loop() {
thing.handle();
modbus_update();
}
kemudian upload ke arduino.
lalu cek di web thinger.io apakah sudah connect
jika sudah connect, lanjut membuat dashboard thinger.io
bila ada yang kurang jelas silahkan tanya ke SIMOR
Tidak ada komentar:
Posting Komentar