nbiot mqtt test
Dependencies: mbed itoa DFRobot_SIM7000-master millis
Diff: main.cpp
- Revision:
- 0:8864eb729b32
- Child:
- 1:450535d62644
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri May 10 07:10:39 2019 +0000 @@ -0,0 +1,60 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); +Serial modbus(PB_9, PB_8,9600);//(tx,rx,baud) + +DigitalOut DE_RE(PB_0); + + +void PC_callback() { + // Note: you need to actually read from the serial to clear the RX interrupt + //modbus.printf("PC_callback\r\n"); + modbus.putc(pc.getc()); +} +void MODBUS_callback() { + //pc.printf("MODBUS_callback\r\n"); + pc.putc(modbus.getc()); +} + +int main() { + pc.attach(&PC_callback); + modbus.attach(&MODBUS_callback); + while(1) { + + /* + if(pc.readable()) { + modbus.putc(pc.getc()); + pc_activity = !pc_activity; + } + */ + DE_RE=1; + + modbus.putc(0x01); + modbus.putc(0x03); + modbus.putc(0x00); + modbus.putc(0x00); + modbus.putc(0x00); + modbus.putc(0x01); + modbus.putc(0x84); + modbus.putc(0x0A); + //wait(3); + wait_ms(2); + DE_RE =0 ; + /* + modbus.putc(0x31); + //} + //DE_RE =0 ; + //wait(0.1); + + + if(modbus.readable()>0) { + pc.printf("modbus read something\r\n"); + pc.putc(modbus.getc()); + } else{ + pc.printf("modbus read nothing\r\n"); + } + + */ + wait(10); + } +} \ No newline at end of file