some docs
This commit is contained in:
BIN
docs/IMG_3853.jpg
Normal file
BIN
docs/IMG_3853.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 MiB |
BIN
docs/IMG_3854.jpg
Normal file
BIN
docs/IMG_3854.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 MiB |
BIN
docs/IMG_3855.jpg
Normal file
BIN
docs/IMG_3855.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 MiB |
BIN
docs/modbus01.png
Normal file
BIN
docs/modbus01.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
@ -4,6 +4,15 @@
|
|||||||
#include <ArduinoModbus.h>
|
#include <ArduinoModbus.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define RX_PIN 7
|
||||||
|
#define TX_PIN 6
|
||||||
|
#define RE_PIN 5
|
||||||
|
#define DE_PIN 4
|
||||||
|
#define LED_RED 3
|
||||||
|
#define LED_GREEN 2
|
||||||
|
#define LED_BLUE 45
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* OTAA para*/
|
/* OTAA para*/
|
||||||
uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 };
|
uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 };
|
||||||
@ -62,6 +71,7 @@ uint8_t appPort = 2;
|
|||||||
uint8_t confirmedNbTrials = 4;
|
uint8_t confirmedNbTrials = 4;
|
||||||
|
|
||||||
RS485Class* pRS485_1;
|
RS485Class* pRS485_1;
|
||||||
|
ModbusRTUClientClass* pModbusClient;
|
||||||
|
|
||||||
/* Prepares the payload of the frame */
|
/* Prepares the payload of the frame */
|
||||||
static void prepareTxFrame( uint8_t port )
|
static void prepareTxFrame( uint8_t port )
|
||||||
@ -73,11 +83,24 @@ static void prepareTxFrame( uint8_t port )
|
|||||||
*for example, if use REGION_CN470,
|
*for example, if use REGION_CN470,
|
||||||
*the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h".
|
*the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h".
|
||||||
*/
|
*/
|
||||||
appDataSize = 4;
|
appDataSize = 8;
|
||||||
appData[0] = 0x10;
|
|
||||||
appData[1] = 0x21;
|
Serial.println("modbus operation");
|
||||||
appData[2] = 0x32;
|
|
||||||
appData[3] = 0x43;
|
long v1 = pModbusClient->inputRegisterRead(7, 0x01);
|
||||||
|
Serial.print("v1: ");
|
||||||
|
Serial.println(v1);
|
||||||
|
memcpy(appData, &v1, 4);
|
||||||
|
|
||||||
|
long v2 = pModbusClient->inputRegisterRead(7, 0x02);
|
||||||
|
Serial.print("v2: ");
|
||||||
|
Serial.println(v2);
|
||||||
|
memcpy(appData+4, &v2, 4);
|
||||||
|
|
||||||
|
//appData[0] = 0x10;
|
||||||
|
//appData[1] = 0x21;
|
||||||
|
//appData[2] = 0x32;
|
||||||
|
//appData[3] = 0x43;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if true, next uplink will add MOTE_MAC_DEVICE_TIME_REQ
|
//if true, next uplink will add MOTE_MAC_DEVICE_TIME_REQ
|
||||||
@ -85,10 +108,18 @@ static void prepareTxFrame( uint8_t port )
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial1.begin(9600, SERIAL_8N1, 7, 6);
|
Serial1.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN);
|
||||||
pRS485_1 = new RS485Class(Serial1, 6, 5, 4);
|
pRS485_1 = new RS485Class(Serial1, TX_PIN, RE_PIN, DE_PIN);
|
||||||
ModbusRTUClient.begin(*pRS485_1, 9600, SERIAL_8N1);
|
pModbusClient = new ModbusRTUClientClass(*pRS485_1);
|
||||||
|
pModbusClient->begin(9600, SERIAL_8N1);
|
||||||
|
|
||||||
|
pinMode(LED_BLUE, OUTPUT);
|
||||||
|
digitalWrite(LED_BLUE, LOW);
|
||||||
|
pinMode(LED_RED, OUTPUT);
|
||||||
|
digitalWrite(LED_RED, LOW);
|
||||||
|
pinMode(LED_GREEN, OUTPUT);
|
||||||
|
digitalWrite(LED_GREEN, LOW);
|
||||||
|
|
||||||
Mcu.begin();
|
Mcu.begin();
|
||||||
deviceState = DEVICE_STATE_INIT;
|
deviceState = DEVICE_STATE_INIT;
|
||||||
}
|
}
|
||||||
@ -97,9 +128,12 @@ void loop()
|
|||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
|
|
||||||
|
digitalWrite(LED_GREEN, HIGH);
|
||||||
|
|
||||||
switch( deviceState )
|
switch( deviceState )
|
||||||
{
|
{
|
||||||
case DEVICE_STATE_INIT:
|
case DEVICE_STATE_INIT:
|
||||||
|
digitalWrite(LED_GREEN, LOW);
|
||||||
{
|
{
|
||||||
#if(LORAWAN_DEVEUI_AUTO)
|
#if(LORAWAN_DEVEUI_AUTO)
|
||||||
LoRaWAN.generateDeveuiByChipID();
|
LoRaWAN.generateDeveuiByChipID();
|
||||||
@ -113,12 +147,8 @@ void loop()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DEVICE_STATE_SEND:
|
case DEVICE_STATE_SEND:
|
||||||
|
digitalWrite(LED_BLUE, HIGH);
|
||||||
{
|
{
|
||||||
Serial.println("rs485 writing");
|
|
||||||
pRS485_1->beginTransmission();
|
|
||||||
pRS485_1->write(0xaa);
|
|
||||||
pRS485_1->endTransmission();
|
|
||||||
|
|
||||||
Serial.println("sending");
|
Serial.println("sending");
|
||||||
prepareTxFrame( appPort );
|
prepareTxFrame( appPort );
|
||||||
LoRaWAN.send();
|
LoRaWAN.send();
|
||||||
@ -126,6 +156,7 @@ void loop()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DEVICE_STATE_CYCLE:
|
case DEVICE_STATE_CYCLE:
|
||||||
|
digitalWrite(LED_BLUE, LOW);
|
||||||
{
|
{
|
||||||
// Schedule next packet transmission
|
// Schedule next packet transmission
|
||||||
txDutyCycleTime = appTxDutyCycle + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
|
txDutyCycleTime = appTxDutyCycle + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
|
||||||
|
Reference in New Issue
Block a user