Flush serial port (sending AT commands)

Hi, i am trying sending AT command in gsm modem and check conditions. First, I do send "AT" command and modem replied "OK". Next, I do send "AT+CGPS=1" to switch on the gps but system sending again the "AT". I do understand that need to flush the serial port before sending next command. May I know how to flush sserial port.

[{"id":"9f17ec20.55487","type":"tab","label":"GPS","disabled":false,"info":""},{"id":"5a4c7d9c.52d6b4","type":"inject","z":"9f17ec20.55487","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":199,"y":159,"wires":[["cf88cd0d.f69c7"]]},{"id":"13278684.ba0be9","type":"debug","z":"9f17ec20.55487","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","x":577,"y":75,"wires":[]},{"id":"cf88cd0d.f69c7","type":"function","z":"9f17ec20.55487","name":"AT commands","func":"msg.payload = Buffer.from(\"41540D\", \"hex\");\n\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":156,"wires":[["13278684.ba0be9","1ef028cf.1c6c37"]]},{"id":"3bb80dce.f29832","type":"debug","z":"9f17ec20.55487","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":576,"y":449,"wires":[]},{"id":"a976b4ba.e2a618","type":"function","z":"9f17ec20.55487","name":"GPS START","func":"//if (msg.payload.substr(0, 2) == \"OK\")\n//    { \n        //A   T +  C  G  P  S  =  1\n        //41 54 2B 43 47 50 53 3D 31 0D \n        msg.payload = Buffer.from(\"41542B434750533D310D\", \"hex\");\n        return msg; \n//    }","outputs":1,"noerr":0,"x":441,"y":373,"wires":[["3bb80dce.f29832","5c482769.d1f988"]]},{"id":"d09b0e84.db626","type":"debug","z":"9f17ec20.55487","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1033,"y":160,"wires":[]},{"id":"1ef028cf.1c6c37","type":"serial request","z":"9f17ec20.55487","name":"","serial":"35de5004.bbb8f","x":548,"y":155,"wires":[["a8a68acd.f2f0d8","ee60be81.04fb8"]]},{"id":"a8a68acd.f2f0d8","type":"debug","z":"9f17ec20.55487","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":706,"y":122,"wires":[]},{"id":"6bfcd62.cba8f28","type":"serial request","z":"9f17ec20.55487","name":"","serial":"35de5004.bbb8f","x":828,"y":200,"wires":[["d09b0e84.db626","629b1b8a.11db64"]]},{"id":"ee60be81.04fb8","type":"function","z":"9f17ec20.55487","name":"Buffer","func":"\nreturn msg;","outputs":1,"noerr":0,"x":694,"y":198,"wires":[["6bfcd62.cba8f28"]]},{"id":"5c482769.d1f988","type":"serial request","z":"9f17ec20.55487","name":"","serial":"35de5004.bbb8f","x":599,"y":377,"wires":[["9ac57052.409c","3dcbc677.e9c4da"]]},{"id":"9ac57052.409c","type":"function","z":"9f17ec20.55487","name":"Buffer","func":"\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":374,"wires":[["c785dc02.4a4ad"]]},{"id":"c785dc02.4a4ad","type":"serial request","z":"9f17ec20.55487","name":"","serial":"35de5004.bbb8f","x":854,"y":380,"wires":[["c1ddd139.78ca2"]]},{"id":"c1ddd139.78ca2","type":"debug","z":"9f17ec20.55487","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1019,"y":381,"wires":[]},{"id":"3dcbc677.e9c4da","type":"debug","z":"9f17ec20.55487","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":799,"y":453,"wires":[]},{"id":"a0b398b9.ab3048","type":"inject","z":"9f17ec20.55487","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":263,"y":372,"wires":[["a976b4ba.e2a618"]]},{"id":"629b1b8a.11db64","type":"function","z":"9f17ec20.55487","name":"OK conditions","func":"if( msg.payload.substring(0,2) == 'OK'){\n    return msg;\n}","outputs":1,"noerr":0,"x":992,"y":243,"wires":[["a976b4ba.e2a618","d75d363d.dfe618"]]},{"id":"d75d363d.dfe618","type":"debug","z":"9f17ec20.55487","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1194,"y":247,"wires":[]},{"id":"35de5004.bbb8f","type":"serial-port","z":"","serialport":"COM7","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"}]

Your flow sends it twice for some reason...


You don't need to flush it - once it has sent it has been flushed.

Hi, upon sending

//  AT CR
msg.payload = Buffer.from("41540D", "hex");

I am unable to get result (OK). without empty buffer between.

I don't know but have you tried adding 0A to the message (Line Feed). Currently you just have Carriage Return.

[{"id":"9f17ec20.55487","type":"tab","label":"GPS","disabled":false,"info":""},{"id":"5a4c7d9c.52d6b4","type":"inject","z":"9f17ec20.55487","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":199,"y":159,"wires":[["cf88cd0d.f69c7"]]},{"id":"cf88cd0d.f69c7","type":"function","z":"9f17ec20.55487","name":"AT commands","func":"msg.payload = Buffer.from(\"41540D\", \"hex\");\n\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":156,"wires":[["1ef028cf.1c6c37"]]},{"id":"1ef028cf.1c6c37","type":"serial request","z":"9f17ec20.55487","name":"","serial":"35de5004.bbb8f","x":542,"y":160,"wires":[["3dcbc677.e9c4da"]]},{"id":"3dcbc677.e9c4da","type":"debug","z":"9f17ec20.55487","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":722,"y":160,"wires":[]},{"id":"25f55021.2e15d","type":"serial in","z":"9f17ec20.55487","name":"","serial":"35de5004.bbb8f","x":186,"y":256,"wires":[["7a9662b5.b49d4c"]]},{"id":"7a9662b5.b49d4c","type":"debug","z":"9f17ec20.55487","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":366,"y":256,"wires":[]},{"id":"35de5004.bbb8f","type":"serial-port","z":"","serialport":"COM7","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"}]

I don't understand. Are you asking a different question now?