Giter VIP home page Giter VIP logo

arduino-cmdmessenger's Introduction

CmdMessenger

License

A messaging library for the Arduino and .NET/Mono platform

C# Build status: C# Build status

VB# Build status: VB Build status

Arduino Build status: Build Status

Introduction

CmdMessenger is a messaging library for the Arduino Platform (and .NET/Mono platform). It supports multiple transport layers: serial port over USB, Bluetooth, TCP/IP (under development)

The message format is:

Cmd Id, param 1, [...] , param N;

Although the field separator ',' and command separator ';' can be changed

The library can

  • both send and receive of commands
  • Both write and read multiple arguments
  • Both write and read all primary data types
  • Attach callback functions any received command

The library supports any primary data types, and zero to many multiple arguments. Arguments can either be sent in plain text (to be human readable) or in binary form (to be efficient).

With version 3.x also comes a full implementation of the toolkit in C#, which runs both in Mono (http://monodevelop.com/Download) and Visual Studio (http://www.microsoft.com/visualstudio/eng#downloads) This allows for full 2-way communication between the arduino controller and the PC.

If you are looking for a Python client to communicate with, please have a look at PyCmdMessenger

Requirements

* Earlier versions of the Arduino IDE will probably work but have not been tested.

Downloading

This package can be downloaded in different manners

  1. Go to https://github.com/thijse/Arduino-CmdMessenger
  2. Click the DOWNLOAD ZIP button in the panel on the
  3. Rename the uncompressed folder Arduino-CmdMessenger-master to CmdMessenger.
  4. You may need to create the libraries subfolder if its your first library.
  5. Place the CmdMessenger library folder in your arduinosketchfolder/libraries/ folder.
  6. Restart the IDE.
  7. For more information, read this extended manual
  • If you want to have a package that includes all referenced libraries, use the pre-packaged library
  1. Download the package as a zipfile here or as a tarball here .
  2. Copy the folders inside the libraries folder to you your arduinosketchfolder/libraries/ folder.
  3. Restart the IDE.
  4. For more information, read this extended manual

Getting Started

Get to know the library, by trying the examples,from simple to complex:

Receive

The 1st example will make the PC toggle the integrated led on the Arduino board.

  • On the Arduino side, it demonstrates how to:
    • Define commands
    • Set up a serial connection
    • Receive a command with a parameter from the PC
  • On the PC side, it demonstrates how to:
    • Define commands
    • Set up a serial connection
    • Send a command with a parameter to the Arduino

SendandReceive

This example expands the previous Receive example. The Arduino will now send back a status. On the Arduino side,

  • it demonstrates how to:
    • Handle received commands that do not have a function attache
    • Send a command with a parameter to the PC
  • On the PC side, it demonstrates how to:
    • Handle received commands that do not have a function attached
    • Receive a command with a parameter from the Arduino

SendandReceiveArguments

This example expands the previous SendandReceive example. The Arduino will now receive multiple and sent multiple float values.

  • On the arduino side, it demonstrates how to:
    • Return multiple types status
    • Receive multiple parameters,
    • Send multiple parameters
    • Call a function periodically
  • On the PC side, it demonstrates how to:
    • Send multiple parameters, and wait for response
    • Receive multiple parameters
    • Add logging events on data that has been sent or received

SendandReceiveBinaryArguments

This example expands the previous SendandReceiveArguments example. The Arduino will receive and send multiple Binary values, demonstrating that this is more efficient way of communication.

  • On the Arduino side, it demonstrates how to:
    • Send binary parameters
    • Receive binary parameters
  • On the PC side, it demonstrates how to:
    • Receive multiple binary parameters,
    • Send multiple binary parameters
    • How callback events can be handled while the main program waits
    • How to calculate milliseconds, similar to Arduino function Millis()

DataLogging

This example expands the previous SendandReceiveArguments example. The PC will now send a start command to the Arduino, and wait for a response from the Arduino. The Arduino will start sending analog data which the PC will plot in a chart

This example shows how to :

  • Use CmdMessenger in combination with GUI applications
  • Use CmdMessenger in combination with ZedGraph
  • Use the StaleGeneralStrategy

ArduinoController

This example expands the SendandReceiveArguments example. The PC will now sends commands to the Arduino when the trackbar is pulled. Every TrackBarChanged events will queue a message to the Arduino to set the blink speed of the internal / pin 13 LED

This example shows how to :

  • use CmdMessenger in combination with GUI applications
  • use CmdMessenger in combination with ZedGraph
  • Send queued commandssds
  • use the CollapseCommandStrategy

SimpleWatchdog

This example shows the usage of the watchdog for communication over virtual serial port:

  • Use auto scanning and connecting
  • Use watchdog

SimpleBluetooth

This example shows the usage of the watchdog for communication over Bluetooth, tested with the well known JY-MCU HC-05 and HC-06 On Arduino side, this uses the SimpleWatchdog.ino script as the previous example

  • Use bluetooth connection
  • Use auto scanning and connecting
  • Use watchdog

TemperatureControl

This example expands the previous ArduinoController example. The PC will now send a start command to the Arduino, and wait for a response from the Arduino. The Arduino will start sending temperature data and the heater steering value data which the PC will plot in a chart. With a slider we can set the goal temperature, which will make the PID software on the controller adjust the setting of the heater.

This example shows how to design a responsive performance UI that sends and receives commands

  • Send queued commands
  • Add queue strategies

ConsoleShell

This example shows how to use CmdMessenger as a shell, and communicate with it using the Serial Console This example is different from the others:

  • there is no PC counterpart
  • it will only receive commands, instead of sending
  • commands it will use Serial.Print

Below is an example of interacting with the sample:

   Available commands
   0;                  - This command list
   1,<led state>;      - Set led. 0 = off, 1 = on
   2,<led brightness>; - Set led brighness. 0 - 1000
   3;                  - Show led state
  
 Command> 3;
  
  Led status: on
  Led brightness: 500
  
 Command> 2,1000;
  
   Led status: on
   Led brightness: 1000
  
 Command> 1,0;
  
   Led status: off
   Led brightness: 1000

All samples are heavily documented and should be self explanatory.

  1. Open the Example sketch in the Arduino IDE and compile and upload it to your board.
  2. Open de CmdMessenger.sln solution in Visual Studio or Mono Develop/Xamarin Studio
  3. Set example project with same name as the Arduino sketch as start-up project, and run
  4. Enjoy!

Trouble shooting

  • If the PC and Arduino are not able to connect, chances are that either the selected port on the PC side is not correct or that the Arduino and PC are not at the same baud rate. Try it out by typing commands into the Arduino Serial Monitor, using the ConsoleShell
  • Some boards (e.g. Sparkfun Pro Micro) need DtrEnable set to be true.
  • If the port and baud rate are correct but callbacks are not being invoked, try looking at logging of sent and received data. See the SendandReceiveArguments project for an example.
  • If you have a problem that is hard to pinpoint, use the CommandMessengerTests testsuite. This project runs unit tests on several parts on the mayor parts of the CmdMessenger library. Note that the primary function is not to serve as an example, so the code may be less documented and clean as the example projects.

Notes

An example for use with Max5 / MaxMSP was included up until version 2. (it can still be found here https://github.com/dreamcat4/CmdMessenger). Since we have not been able to check it wil Max/MaxMSP, the example was removed.

Changelog

CmdMessenger v4.0.0

  • [Arduino] Additional autoConnect sample
  • [.Net/.Mono] Full Threading redesign.
  • [.Net/.Mono] AutoConnect & watchdog functionality.
  • [.Net/.Mono] Tested Linux compatibility
  • [.Net/.Mono] Visual Basic samples.
  • [.Net/.Mono] Native Bluetooth support (windows only)

CmdMessenger v3.6

  • [Arduino] Bugfix: approx 1 in 1000 commands failed, when multiple binary parameters are sent over
  • [Arduino] Bugfix: Binary sending of non-number would give compile time error
  • [Arduino] feature: Posibility to send command without argument
  • [Arduino] feature: Posibility to send floats with scientific notation, to get full float range
  • [.Net/.Mono] Added Unit tests
  • [.Net/.Mono] Consistent variables on .NET and Arduino side.
  • [.Net/.Mono] Major performance improvement (for boards like Teensy 3), by combining queued commands

CmdMessenger v3.5

  • [Arduino] Added console shell sample
  • [Arduino] Minor performance improvement
  • [.Net/.Mono] Minor performance improvement

CmdMessenger v3.4

  • [Arduino] Bug-fix in receiving binary values
  • [.Net/.Mono] Bug-fix that makes communication 100x (!) faster, while lowering system load
  • [.Net/.Mono] Added function to run on single core

CmdMessenger v3.3

  • [Arduino] Speed improvements for Teensy

CmdMessenger v3.2

  • [All] Clean transport layer interface makes it easy to implement other transport modes (Bluetooth, ZigBee, Web), even if they do not implement a virtual serial port
  • [.Net/.Mono] Adaptive throttling to work with transport layers of any speed
  • [.Net/.Mono] Smart queuing for smooth running applications and no hanging UI
  • [Arduino] Small fixes and sending long argument support

CmdMessenger v3.1

  • Adds 2 GUI examples

CmdMessenger v3.0

  • Wait for acknowlegde commands
  • Sending of common type arguments (float, int, char)
  • Multi-argument commands
  • Escaping of special characters in strings
  • Sending of binary data of any type (uses escaping, no need for Base-64 Encoding)
  • Bugfixes
  • Added code documentation
  • Added multiple samples

CmdMessenger v2

  • Updated to work with Arduino IDE 022
  • Enable / disable newline (print and ignore)
  • New generic example (works with all Arduinos)
  • More reliable process() loop.
  • User can set their own cmd and field seperator (defaults to ';' and ',')
  • Base-64 encoded data to avoid collisions with ^^
  • Works with Arduino Serial Monitor for easy debugging

Credit

  • Initial Messenger Library - Thomas Ouellet Fredericks.
  • CmdMessenger Version 1 - Neil Dudman.
  • CmdMessenger Version 2 - Dreamcat4.
  • CmdMessenger Version 3 - Thijs Elenbaas
  • CmdMessenger Version 4 - Thijs Elenbaas & Valeriy kucherenko

On using and modifying libraries

Copyright

CmdMessenger is provided Copyright © 2013,2014,2015,2016, 2017 under MIT License.

arduino-cmdmessenger's People

Contributors

bigredaye avatar gandy92 avatar ivankravets avatar palatis avatar singajeet avatar thijse avatar valkuc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-cmdmessenger's Issues

The available() should return Current!=null;

For variable number of arguments, this code will not work:

while (cmdMessenger.available())
{
      int curNo=cmdMessenger.readInt16Arg();
      
      // Do something with this number.
}

It will skip 1 parameter at a time. Was this function intended for this?

Nuget package

Hey Thijs, thanks for the great library! I was trying to implement virtually the same thing myself, but it was taking too long and had some nasty bugs. Stumbling upon this has got me up and running once again with minimal effort.

I have created some nuget packages for CmdMessenger to make it easier to install and use in Visual Studio projects - just wanted to know if you are happy for me to publish and maintain them on nuget.org

I have split the bluetooth transport layer into it's own package as it has a dependency (just keeps the core package nice and lean).

ConsoleShell not doing anything

On my Pro Mini 5V 16MHz I have used the "Communications - SerialEvent" example to prove I can send and receive to the board. I load up the ConsoleShell example and it displays the console options but ignores all input.

In fact none of the examples react to serial monitor input.

Does the library work with the Pro Mini?

New Python Interface

Hi Thijs,

Thanks for the great library. I've found it quite useful.

I've written a Python interface for an arduino running the CmdMessenger library called PyCmdMessenger (https://github.com/harmsm/PyCmdMessenger). I built this specifically for communication between a raspberry pi and arduino over USB.

Before I put the Python code onto Pip, I wanted to check with you and make sure you're fine with my use of the PyCmdMessenger name. Also, if you like the Python interface, it might also be worth linking to my project from the main CmdMessenger page. There are a huge number of python-centric raspberry pi users that would find the Arduino-CmdMessenger + PyCmdMessenger combination useful.

Thanks,

Mike

commands coming from arduino have to be sent 2 times

Any command coming from the arduino has to be send twice before the attached method on the c# console program fires. Ive tried lowering the baud rate to 9600 and setting DTR enabled to true.
Using a DFRduino UNO v3.0

compatibility with ESP8266 / WeMos D1 Mini

Hey all,

is this library compatible with the D1? My goal is to use it as interface between an Arduino Uno and the D1 over Serial. However I can't seem to compile any of the example files for the D1, which work just fine on the Uno.

Can you tell me if this an problem on my side or within the library?

Thanks a bunch!

Build Log:


Arduino: 1.8.5 (Linux), Board: "WeMos D1 R2 & mini, 80 MHz, Flash, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

/home/anselm/Downloads/arduino-1.8.5/arduino-builder -dump-prefs -logger=machine -hardware /home/anselm/Downloads/arduino-1.8.5/hardware -hardware /home/anselm/Arduino/hardware -tools /home/anselm/Downloads/arduino-1.8.5/tools-builder -tools /home/anselm/Downloads/arduino-1.8.5/hardware/tools/avr -built-in-libraries /home/anselm/Downloads/arduino-1.8.5/libraries -libraries /home/anselm/Arduino/libraries -fqbn=esp8266com:esp8266:d1_mini:CpuFrequency=80,VTable=flash,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,FlashErase=none,UploadSpeed=115200 -ide-version=10805 -build-path /tmp/arduino_build_792499 -warnings=none -build-cache /tmp/arduino_cache_76518 -prefs=build.warn_data_percentage=75 -verbose /home/anselm/Arduino/libraries/CmdMessenger/examples/Receive/Receive.ino
/home/anselm/Downloads/arduino-1.8.5/arduino-builder -compile -logger=machine -hardware /home/anselm/Downloads/arduino-1.8.5/hardware -hardware /home/anselm/Arduino/hardware -tools /home/anselm/Downloads/arduino-1.8.5/tools-builder -tools /home/anselm/Downloads/arduino-1.8.5/hardware/tools/avr -built-in-libraries /home/anselm/Downloads/arduino-1.8.5/libraries -libraries /home/anselm/Arduino/libraries -fqbn=esp8266com:esp8266:d1_mini:CpuFrequency=80,VTable=flash,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,FlashErase=none,UploadSpeed=115200 -ide-version=10805 -build-path /tmp/arduino_build_792499 -warnings=none -build-cache /tmp/arduino_cache_76518 -prefs=build.warn_data_percentage=75 -verbose /home/anselm/Arduino/libraries/CmdMessenger/examples/Receive/Receive.ino
Using board 'd1_mini' from platform in folder: /home/anselm/Arduino/hardware/esp8266com/esp8266
Using core 'esp8266' from platform in folder: /home/anselm/Arduino/hardware/esp8266com/esp8266
Detecting libraries used...
"/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/lwip2/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/libc/xtensa-lx106-elf/include" "-I/tmp/arduino_build_792499/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_WEMOS_D1MINI -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_WEMOS_D1MINI"   -DESP8266 "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/cores/esp8266" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/variants/d1_mini" "/tmp/arduino_build_792499/sketch/Receive.ino.cpp" -o "/dev/null"
"/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/lwip2/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/libc/xtensa-lx106-elf/include" "-I/tmp/arduino_build_792499/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_WEMOS_D1MINI -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_WEMOS_D1MINI"   -DESP8266 "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/cores/esp8266" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/variants/d1_mini" "-I/home/anselm/Arduino/libraries/CmdMessenger" "/tmp/arduino_build_792499/sketch/Receive.ino.cpp" -o "/dev/null"
Using cached library dependencies for file: /home/anselm/Arduino/libraries/CmdMessenger/CmdMessenger.cpp
Using cached library dependencies for file: /home/anselm/Arduino/libraries/CmdMessenger/utility/DoEvery.cpp
"/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/lwip2/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/libc/xtensa-lx106-elf/include" "-I/tmp/arduino_build_792499/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_WEMOS_D1MINI -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_WEMOS_D1MINI"   -DESP8266 "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/cores/esp8266" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/variants/d1_mini" "-I/home/anselm/Arduino/libraries/CmdMessenger" "-I/home/anselm/Arduino/libraries/CmdMessenger/utility" "/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp" -o "/dev/null"
Generating function prototypes...
"/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/lwip2/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/libc/xtensa-lx106-elf/include" "-I/tmp/arduino_build_792499/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_WEMOS_D1MINI -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_WEMOS_D1MINI"   -DESP8266 "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/cores/esp8266" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/variants/d1_mini" "-I/home/anselm/Arduino/libraries/CmdMessenger" "/tmp/arduino_build_792499/sketch/Receive.ino.cpp" -o "/tmp/arduino_build_792499/preproc/ctags_target_for_gcc_minus_e.cpp"
"/home/anselm/Downloads/arduino-1.8.5/tools-builder/ctags/5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "/tmp/arduino_build_792499/preproc/ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...


"/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/lwip2/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/libc/xtensa-lx106-elf/include" "-I/tmp/arduino_build_792499/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_WEMOS_D1MINI -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_WEMOS_D1MINI"   -DESP8266 "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/cores/esp8266" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/variants/d1_mini" "-I/home/anselm/Arduino/libraries/CmdMessenger" "/tmp/arduino_build_792499/sketch/Receive.ino.cpp" -o "/tmp/arduino_build_792499/sketch/Receive.ino.cpp.o"
Compiling libraries...
Compiling library "CmdMessenger"


Using previously compiled file: /tmp/arduino_build_792499/libraries/CmdMessenger/CmdMessenger.cpp.o
Using previously compiled file: /tmp/arduino_build_792499/libraries/CmdMessenger/utility/DoEvery.cpp.o
"/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/lwip2/include" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/sdk/libc/xtensa-lx106-elf/include" "-I/tmp/arduino_build_792499/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536   -DARDUINO=10805 -DARDUINO_ESP8266_WEMOS_D1MINI -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_WEMOS_D1MINI"   -DESP8266 "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/cores/esp8266" "-I/home/anselm/Arduino/hardware/esp8266com/esp8266/variants/d1_mini" "-I/home/anselm/Arduino/libraries/CmdMessenger" "-I/home/anselm/Arduino/libraries/CmdMessenger/utility" "/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp" -o "/tmp/arduino_build_792499/libraries/CmdMessenger/utility/HeaterSim.cpp.o"


/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp: In member function 'void HeaterSim::CalcTemperature()':
/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:73:72: error: no matching function for call to 'max(long unsigned int, int)'
  if (currentTime >= _lastTime) _deltams = max(currentTime - _lastTime,1);
                                                                        ^
/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:73:72: note: candidates are:
In file included from /home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/algorithm:62:0,
                 from /home/anselm/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Arduino.h:254,
                 from /home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.h:25,
                 from /home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:23:
/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4236:5: note: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^
/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4236:5: note:   template argument deduction/substitution failed:
/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:73:72: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
  if (currentTime >= _lastTime) _deltams = max(currentTime - _lastTime,1);
                                                                        ^
In file included from /home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/algorithm:62:0,
                 from /home/anselm/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Arduino.h:254,
                 from /home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.h:25,
                 from /home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:23:
/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4231:5: note: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^
/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4231:5: note:   template argument deduction/substitution failed:
/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:73:72: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
  if (currentTime >= _lastTime) _deltams = max(currentTime - _lastTime,1);
                                                                        ^
In file included from /home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/algorithm:61:0,
                 from /home/anselm/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Arduino.h:254,
                 from /home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.h:25,
                 from /home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:23:
/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:260:5: note: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:260:5: note:   template argument deduction/substitution failed:
/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:73:72: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
  if (currentTime >= _lastTime) _deltams = max(currentTime - _lastTime,1);
                                                                        ^
In file included from /home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/algorithm:61:0,
                 from /home/anselm/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Arduino.h:254,
                 from /home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.h:25,
                 from /home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:23:
/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:216:5: note: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^
/home/anselm/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:216:5: note:   template argument deduction/substitution failed:
/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:73:72: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
  if (currentTime >= _lastTime) _deltams = max(currentTime - _lastTime,1);
                                                                        ^
Using library CmdMessenger at version 4.0.0 in folder: /home/anselm/Arduino/libraries/CmdMessenger 
exit status 1
Error compiling for board WeMos D1 R2 & mini.

Maximum baud rate

Hi, I am trying to use CmdMessenger library with over 115200 bps baud rate but didn't have any success. I uploaded a test sketch which sends a value with 250000 bps (using the library). When I opened the serial monitor in Arduino IDE, I can see the values. But the C# program was not triggering the callback routines (even if baud rate was correct). So I think the receiving end is the problem because it does not work although the values are being sent correctly.

compile error

Encountered the following error when attempting to compile a sketch using CmdMessenger:

Arduino-CmdMessenger/CmdMessenger.cpp:492:9: error: invalid conversion from 'char' to 'char*' [-fpermissive]
  return '\0';

The function is defined to return a pointer as follows;

char* CmdMessenger::readStringArg()

Since the function is returning a char instead of a pointer, this is causing a compiler error.

Should the correct return value be NULL? ie:

return NULL;

CmdMessengerTest failed with Arduino Uno

environment:
Arduino UNO
Arduino IDE 1.6.11
Visual Studio 2015.3
Windows 10x64

prepare CommandMessengerTests:
var device = arduinoNano;
PortName = "COM7"

run CommandMessengerTests (x86, Release)

*** Test Summary ****

Some test sets failed!! 
Test sets passed: 2
Test sets failed: 4

TestLogFile.txt: https://pastebin.com/wZCkLBT4

[Feature Request] Checksum for wireless connection

I am controlling an rc vehicle with your lib, but I have the problem that I need a crc (8 or 16) to check the data (connection over Xbee). But I have no idea how I can make that.

Sorry for my english :)

Publish CmdMessenger client as NuGet package

As a software developer I can manage the C# CmdMessenger client through NuGet so that I don't have to manually deal with the repository dependency in my development environment.

Hello @thijse, i have been using 3.6 for so many years and I discovered a bug recently so that I want to update to 4.2 - i had CmdMessenger always included in my projects repository which obviously is not great.

First thing i expected was that there would be a NuGet package available. It's so convenient for adding it to your projects dependencies.

Let's publish the C# client as package - that will be great. I am happy to provide a github workflow to do that during release automatically.

Related issue: #34

some unescape() are missing

There is no unescape in:
readStringArg()
copyStringArg()
compareStringArg()

So you got (with ID=1) from readStringArg() for the transmitted string:

1,Hello\,World\;Or what?;

"Hello\,World\;Or what?"
Of course you can unescape this no in user sketch, but I think, this is not as it should be?

Platformio complains about a missing dependancy

[Fri Jun 16 11:09:17 2017] Processing mega (platform: atmelavr, lib_deps: SdFat, Thread, https://github.com/FastLED/FastLED.git, https://github.com/thijse/Arduino-CmdMessenger.git, upload_speed: 115200, board: megaatmega2560, framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Converting main.ino
Collected 50 compatible libraries
Looking for dependencies...
Error: Could not find `Adafruit-MAX31855` dependency for `CmdMessenger` library
========================================================================================================================= [ERROR] Took 2.01 seconds =========================================================================================================================

my platformio.ini file:

[common]


[env:mega]
platform = atmelavr
framework = arduino
board = megaatmega2560
upload_speed = 115200
lib_deps =
    SdFat
    Thread
    https://github.com/FastLED/FastLED.git
    https://github.com/thijse/Arduino-CmdMessenger.git

I think it's because the library in question is named Adafruit MAX31855 library : http://platformio.org/lib/show/84/Adafruit%20MAX31855%20library/installation

Porting to energia ide for tm4c123g

I was planning to use freertos and tm4c123g but i have already done a project using your library
Thank you for sharing this library
I am planning to port it to energia ide which is similar to arduino ide but for tm4c123

How hard is it to port?

ReceivedCommandSignal does not work on my Arduino Uno

Hi,

I am having an issue with the blocked/sync calls, even with the example.
The response is never received from the arduino. Even if I increase the timeout value to 5 sec. It won't help.

Steps to reproduce:

  • Upload sketch SendAndReceiveArguments to Arduino Uno (CH340 chip)
  • Run C# example SendAndReceiveArguments

Expected result:

  • Response: Result of sum and difference

Actual result:

  • No Response

I have tried dtrEnabled with both values (true, false)
When I use the SerialMonitor of the ArduinoIDE and just send the plain command the response is correct and immediate. So it must be in the blocking-code portion on the C# client side. I have spent an hour of debugging but I cannot see the reason. Maybe something with the suspended ReceiveQueue?

Esp8266 OR Ethernet connectivity

Hi!

Thank you very much for this great piece of software , it helped me a lot in my projects previously. There is an interface for TCP in .Net library for CmdMessenger but it lacks an example on the Arduino side, can you please give us a pointer to how to use this or an example will be highly appreciated. I want to connect an Esp8266 / Ethernet shield to the PC / Raspberry side with GUI and stuff.

Best Regards!

Sending command via Arduino USB port causes reset

I am using an Arduino Mega 2560 and PyCmdMessenger.
When I send a simple acknowledge type message to the Arduino through the built-in USB/Serial interface it causes a reset of the Arduino.
However if I connect a external USB/Serial convertor directly to the Tx/Rx pins of the Arduino then it works , no problem.
The Arduino USB/Serial port works normally when not using CmdMessenger (ie for looking at debugging messages in tera term).
I can't work out what is causing the reset - or is this possibly a problem with PyCmdMessenger and the way it handles connections?

sendCmd can't wait for a response in a typical RS-485 configuration.

I'm using RS-485 in a single-duplex, master-slave arrangement. After transmitting a command, the master must turn off its line driver to allow the slave to respond. This means that I can't use sendEndCmd()'s optional ackCmdId and timeout arguments, since the line driver will still be active when blockedTillReply() runs.

In my my copy, I've added a public waitForReply() that simply wraps the private blockedTillReply(). With that change, the master can sendCmdEnd(), turn off it's driver, and then waitForReply(). This works fine for me. But maybe you have a more creative solution.

2 usage questions

Hi,

Sorry to use the issues to ask questions, but I couldn't find a group/forum for this library.
I have started using the library it looks great!

I did manage to get confused about 2 things:

  1. How can I check how many arguments are present in a call ? In a scenario where a variable number of arguments is passed, how can I could the arguments ? (I've noticed that trying to read an argument that isn't there there returns 0.0 for readFloatArg() for example. Is there something I might have missed that already handles argument count ?)
  2. I haven't managed to properly use the SendAndReceiveBinaryArguments function. All I could get the sketch to react to was sending a 0; as binary (0x00 0x3B). I don't think I understood how the binary communication works. Hints ? :)

Thank you,
George

Platformio+Digispark compatible solution

I want to use CmdMessenger with Digispark attiny85.

They have their own Stream class, Print classes.. .

  1. First of all I add some functions to Stream class.
int timedRead()
virtual size_t readBytes(char *buffer, size_t length)
  1. I spend a lot of time to find a problem why CmdMessenger can't hear me (only UnknownCommand handler called) ... (I connect Arduino to COM port and want to send-receive bytes in Terminal)

I was angry when I found solution:

Send command 0 
30 3B
Receive command 1
01 2C 33 3B

Digispark made print function without default argument=DEC... for all types except char..
For compatible we should add DEC everywhere in CmdMessenger :(.

comms->print(cmdId, DEC);

and etc

  1. Attiny85 doesn't want to start with CmdMessenger cause little memory.
    I change defines:
#define MAXCALLBACKS        5   // The maximum number of commands   (default: 50) 
#define MESSENGERBUFFERSIZE 20   // The length of the commandbuffer  (default: 64)
#define MAXSTREAMBUFFERSIZE 20  // The length of the streambuffer   (default: 64)

and it works fine :)

There was difficult to find solutions cause:

  1. There is no protocol description or trace. Please add them.
  2. There is no tests written on "C" or "Python" :)

Reading a string messes up all the arguments.

I've been using CmdMessenger for a while and it seemed to work, however my current application requires the reception of a string through serial. Here's the function:

void onBtChName() {
  sendAck(kACK, kBT_CHNAME, F("Storing new name."));
  uint8_t len = constrain(cmdMessenger.readInt16Arg(), 0, 30);
  cmdMessenger.copyStringArg(bt_newname, len+1);
  Serial.print("New name ");
  Serial.write(bt_newname, len);
  Serial.println(len);
  bt_newnamelen = len;
  bt_chname = true;
  sendAck(kDONE, kBT_CHNAME, F("New name stored. Please commit."));
}

This is the callback attached to kBT_CHNAME, which is command 15. I'd expect it to read two arguments, an integer and a string. However it does not work. If I comment out the string reading part, everything works fine (ex. if I send 15,12,34,56,78;, the len variable would contain 12 as I would expect). However, if I also read the string (which is odd, as the string is read after the integer), it skips two arguments. So while 15,9,Davideddu; does not work, 15,0,0,9,Davideddu; does. Another example, if I send 15,12,34,56,78; len would be set to 56 (actually 30 because of constrain, but it doesn't really matter) and bt_newname would contain 78 + 28 bytes of crap.

This is a pretty odd bug.

P.S.: I wrote a python port of CmdMessenger with a similar API that, however, tries to make use of Python-specific features. you can find it here. I'll document it and add a readme at some point.

Problem with SerialTransport

Hi!
My name is Piotr and I want to ask You for a little help with cmdMessenger and CSharp. I’m not sure is this place appropriate, but I decided to try.
I don’t know what I’m doing wrong, by I can’t help myself with “private SerialTransport _serialTransport;”
My English is not good so maybe I show You on picture:

cmdMess1

cmdMess2

cmdMess3

What I’m doing wrong?

Serial exception on Sleep and Disconnect.

So I am using cmdMessenger on a USB serial connection using the watchdog. Every time I sleep my computer and pull my desktop off the docking station. Once when the laptop wakes up I will get the following error and the app crashes.

System.ObjectDisposedException was unhandled Message: An unhandled exception of type 'System.ObjectDisposedException' occurred in mscorlib.dll Additional information: Safe handle has been closed

looking at a similar problem I found this.
https://stackoverflow.com/questions/3230311/problem-with-serialport/7471010#7471010

I will do some more research and see if I can find a solution.

EDIT:
BTW using .NET 4.5.2 on x64 Windows 10. It crashes with debugging on and off.

EDIT 2:
Also found this.
https://stackoverflow.com/questions/8927410/objectdisposedexception-when-closing-serialport-in-net-2-0
http://zachsaw.blogspot.com/2010/07/net-serialport-woes.html

EDIT 3:
Couldn't find a trace within the code but enabling traces for native windows code I get this.
Stack trace for SampleWatchdog

mscorlib.dll!System.StubHelpers.StubHelpers.SafeHandleAddRef(System.Runtime.InteropServices.SafeHandle pHandle, ref bool success)
System.dll!System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent()
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()	

version appears to be incorrect

Hi, I was browsing the source code while evaluating CmdMessager and noticed the following inconsistency with the README Changelog:

#define _CMDMESSENGER_VERSION 3_6 // software version of this library

As you can see, CmdMessenger.cpp in the master branch shows version 3_6. However, the Changelog indicates the version is "CmdMessenger v4.0.0".

Wanted new example using nordic uart nrf52 sending binary data

I need assistance, I think the CmdMessenger is a great idea, I have used it to send data from a bno055 from a arduino over USB serial, it works great,

Now I am trying to using BLE uart using a Adafruit nrf52 feather and the Arduino IDE 1.8.1

CmdMessenger cmdMessenger = CmdMessenger(bleuart);
...
// Send the result of the IMU read using quarternions
//cmdMessenger.sendCmd(kQuarternionSend,q0,q1,q2,q3);
cmdMessenger.sendCmdStart(kQuarternionSend);
cmdMessenger.sendCmdBinArg(mySensor.quat.q0);
cmdMessenger.sendCmdBinArg(mySensor.quat.q1);
cmdMessenger.sendCmdBinArg(mySensor.quat.q2);
cmdMessenger.sendCmdBinArg(mySensor.quat.q3);
cmdMessenger.sendCmdEnd();
}

My problem is that when I use the string version cmdMessenger.sendCmdArg(mySensor.quat.q2);
the terminal shows each character on a new line !
So I am thinking something is wrong on a basic level, when sending a normal
bleuart.println("String to be Printed");
It comes out in one line on the receiver on arduino ble uart app.

I want to change to binary format for the quaternion data so that the message can be sent in one BLE notification / message.
This should be most efficient!

Can anyone assist?

Bo-Erik

I just need to send strings between my arduino and the pi

anyone have a simple example of how to send a string to the ardino and send a string to the pi?
If I can send a string back and forth than I can do anything need in my code.
if I can get the pi to send the arduino "Hi im the PI" and the ardino to send "Nice to meet you" I can do anything else I need. disregard after going through send/receive example a couple tims figured it out

readBin() is not "type-length-safe"

If you use:
uint32_t ui32 = cm.readBinArg();
Then readBinArg() or readBin() will read 4 Bytes from the receiving buffer, ignoring the real length of what is sent and any seperator that may come earlier.
If you send (with ID=1):

1,ABCD;

(with A=0x41, B=0x42, C=0x43, D=0x44) you will get as expected:
0x44434241 = 1145258561.
But if you send:

1,A;

you don't get 0x41 = 65, instead you will get a random value with 0x41 as LSB, 0x00 after it and 2 more "random" bytes from memory.

And ArgOk is not updated.

This should be enhanced with a test if the length (that slpit_r() sees) is big enough, but for this some more changes are needed.

Winforms application not receiving messages from arduino

I have a sample winforms application using CmdMessenger connecting at 115200 with DtrEnable set to true. This is running on windows 10 with Arduino getting connected on COM4. The code is based on the Datalogging example

I have the below code in Setup function in the ino file. The winforms application receives the first acknowledge message. But not the second one. Any clues?

void setup()
{
// Listen on serial connection for messages from the pc
Serial.begin(115200);

// Adds newline to every command
cmdMessenger.printLfCr();

// Attach my application's user-defined callback methods
attachCommandCallbacks();

// Send the status to the PC that says the Arduino has booted
cmdMessenger.sendCmd(kAcknowledge,"Arduino has started!");

// set some pin modes
pinMode(kBlinkLed, OUTPUT);
pinMode(....)

cmdMessenger.sendCmd(kAcknowledge,"Setup Completed");
}

Question - Bluetooth Listener/Server in c#

Hi There,

I think CmdMessenger is great and have it working just fine with serial between my Pi and arduino. Now I want to add a bluetooth connection between a mobile app and my Pi, with the app initiating the connection (ie Pi listening/server).

I'm pretty sure I can follow the example to initiate from the app. What I have no clue about is how to set the Pi (in c#) to listen for a bluetooth connection.

This guy has already done it to some extent, but to be honest I don't trust his code. The client side stuff he wrote is nowhere near as robust as your examples. So I'm hesitant if you have a better way.
https://www.codeproject.com/Articles/842951/CmdMessenger

Any clues are most welcome!

Sincerely,

Richard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.