Author Topic: UniMote : Universal control code for Moteino  (Read 3803 times)

ColinR

  • Full Member
  • ***
  • Posts: 176
UniMote : Universal control code for Moteino
« on: September 07, 2014, 07:59:24 AM »
<< Update, please see: http://www.cupidcontrols.com/2015/03/unimote-v2-read-all-the-rf-things/ >>

Hi All,

Deploying many nodes, I discovered very quickly that I did not want to continually reflash sketches (even though the Moteino has made it easy to do so wirelessly), or reprogram every time I change configuration.

As a result, I set out to create a universal sketch that would handle 99% of the projects I would be working on. A few features:
  • Programmable IO modes, including 1Wire, for all 13 available Moteino IO
  • Eight programmable channels that you can configure inputs, outputs, and read parameters.
  • Data reporting in json-style format on radio and serial, for easy parsing by gateway
  • Storage of configured parameters in EEPROM
  • Built-in and configurable sleep mode and time
  • You can configure all IO and channels by serial or radio by issuing simple commands

All communication sequences are designed to eventually be node-initiated, as nodes will be sleeping except when communicating. They wait for a brief period after data reporting to either receive a command or go to sleep message from the gateway. If they do not receive a message, they go to sleep.

Anyway, the code is young, there are features yet to be included, and tons of optimization left to do. I thought I'd throw this out there to see if anybody finds it useful.

I wrote up a couple pieces here about setting it up and interfacing it with a Pi gateway:

http://www.cupidcontrols.com/2014/09/adventures-in-moteino-modular-communication-for-cupid-remote/
http://www.cupidcontrols.com/2014/09/cupid-remote-read-database-logging-and-ui/

And we're using it with the CuPID Remote units:
http://www.cupidcontrols.com/2014/08/adventures-in-moteino-remote-temperature-monitor/

Node code is here:
https://github.com/iinnovations/iicontrollibs/tree/master/mote

Cheers,
Colin
« Last Edit: March 14, 2015, 04:02:26 AM by ColinR »
CuPID Controls :: Open Source browser-based sensor and device control
Interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

dargs

  • Newbie
  • *
  • Posts: 4
Re: UniMote : Universal control code for Moteino
« Reply #1 on: November 04, 2014, 12:31:27 AM »

Hi Colin,

I'm liking your modular approach, I've been struggling with how to standardise messages to and from moteinos and your method seems to tick all the boxes!

However I'm having some problems :(

Using uni_mote_2p3.ino with arduino 1.05, and current rfm69 library. Moteino R4 without flash.

For any iomode other than 2 (analog), I'm finding my moteino node power cycles straight after sending the value.

In this serial output below, pin 20 as analog is ok, but when i make pin 3 digital in, and enable reporting it power cycles.

Same happens for other pins, set to digital in, or 1-wire..

Have tried other moteinos (with no other hardware connected). and swapped ftdi cables, started commenting out to simplify things, but still no luck..

Any ideas?
thanks, dargs


* removed some 'free memoy' for readability
Quote
Time to check data for pin 20, io number 11
Analog input configured for pin 20
Value: SENDING TO 1
iopin:20,iomode:02,ioval:128.0000
SEND COMPLETE

~modparam;iomode;0;0
processing cmdstring
~modparam;iomode;0;0
Command character received
iomode
Modifying iomode: 0
Changing iomode to: 0

Time to check data for pin 20, io number 11
Analog input configured for pin 20
Value: SENDING TO 1
iopin:20,iomode:02,ioval:122.0000
SEND COMPLETE

BEGIN RECEIVED
nodeid:1, ACK TEST,RX_RSSI:-29
END RECEIVED
Free memory: 571
processing cmdstring
ACK TEST
 - ACK sent

~modparam;ioreportenabled;0;1
Free memory: 529
processing cmdstring
~modparam;ioreportenabled;0;1
Command character received
ioreportenabled
Modifying io: 0
Enabling ioreporting.

~modparam;ioenabled;0;1
Free memory: 541
processing cmdstring
~modparam;ioenabled;0;1
Command character received
ioenabled
Modifying ioenabled: 0
Enabling io.

Time to check data for pin 3, io number 0
Digital input configured for pin 3
SENDING TO 1
iopin:03,iomode:00,iovalue:0000
SEND COMPLETE

SPI Flash Init FAIL! (is chip present?)

Transmitting at 433 Mhz...
I am node id: 8
Free memory: 704


ColinR

  • Full Member
  • ***
  • Posts: 176
Re: UniMote : Universal control code for Moteino
« Reply #2 on: November 04, 2014, 11:33:13 AM »
Glad you enjoy it.

I've noticed this occasionally too and think it must be a memory issue of some sort. In my deployed code I've done loads of commenting and double-checked all strings are stored in flash.

Let me take a look and see if I can't upload a more recent version.

C
CuPID Controls :: Open Source browser-based sensor and device control
Interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

dargs

  • Newbie
  • *
  • Posts: 4
Re: UniMote : Universal control code for Moteino
« Reply #3 on: November 11, 2014, 09:22:32 PM »
Hi Colin,

Quick update -

I found some time to have a bit more of a play, and I think I may have found the source of the lockup/reset I'm experiencing.

The sendlength = 31 for integer values might be too short? I commented it out, so it uses the default 61 chars and it doesn't reboot anymore... I'll have to experiment more to see what effect that then has of sending extra chars.


Quote
void sendIOMessage(byte pin, byte mode, float value) {
  // Initialize send string
//  char sendstring[61];
  int sendlength = 61;  // default
  if (mode == 0 || mode == 1 ) { // for integer values
    //sendlength = 31;
    char sendstring[sendlength];
    sprintf(sendstring, "iopin:%02d,iomode:%02d,iovalue:%04d", pin, mode, value);         
    sendWithSerialNotify(GATEWAYID, sendstring, sendlength);
  Serial.println("just sent send with serial notify"); //debug


dargs

ColinR

  • Full Member
  • ***
  • Posts: 176
Re: UniMote : Universal control code for Moteino
« Reply #4 on: November 18, 2014, 04:57:14 PM »
Interesting.  I may have indeed miscounted by one. The formatted message below is 31 characters, but you need an extra for termination, which would make 32.

"iopin:%02d,iomode:%02d,iovalue:%04d"

I'll give it a shot on my end as well. Coincidentally, I just got my board for my Moteino MEGA based temperature controller in the mail today, so I'll play with it on those.

Thanks for finding that!
C
CuPID Controls :: Open Source browser-based sensor and device control
Interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

ColinR

  • Full Member
  • ***
  • Posts: 176
Re: UniMote : Universal control code for Moteino
« Reply #5 on: March 14, 2015, 04:07:23 AM »
I have hugely upgraded this code. No more segfaults and micro reboots after removal of all string objects and other nifty tricks to save space.

Optimized for remote reconfiguration, detailed command acknowledgement, and use of the same program for remote nodes and also gateway:

http://www.cupidcontrols.com/2015/03/unimote-v2-read-all-the-rf-things/

I've also built a web terminal interface. I'll post a screenshot here and a link to the post:

http://www.cupidcontrols.com/2015/03/rf-mote-web-ui-program-all-the-rf-things/

Below, I'm telling my gateway mote to send a message to node 10, telling the node list configuration parameters and send them to node 1 (the gateway). The reply shows up in the Read Messages.

« Last Edit: March 14, 2015, 04:19:41 PM by ColinR »
CuPID Controls :: Open Source browser-based sensor and device control
Interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com