GLCD Control module for emonCMS

Hello everyone, I've been working on a GLCD control module for emonCMS for a few weeks and thought I'd share.

The idea is that, rather than hard-coding the information to display on the GLCD, I've created an interface that allows the GLCD to be configured via an emonCMS front-end. It also means that the GLCD requests the time from my Raspberry Pi rather than the RPi dumbly broadcasting it every few minutes.

It's not very elegant and there are a few bugs to be ironed out but I think it works as a proof of concept.

The add-on works by setting up the GLCD to broadcast requests to the Raspberry Pi. The RPi then pings back its response while the GLCD waits. Once emonCMS know that it is "feeding" a GLCD node it regularly broadcasts the current "feed". The buttons on the GLCD enable it to request the next/previous feed. The feeds to be broadcast to the GLCD are configured via the emonCMS front end.

Feeds can be configured as "primary" or "secondary" depending on where they might appear on the GLCD unit.

To get it to work you'll need to create a table in your emonCMS database:

CREATE TABLE IF NOT EXISTS `glcd_control` (

  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `nodeId` int(10) unsigned DEFAULT NULL,
  `feedId` int(10) unsigned DEFAULT NULL,
  `feed_name_display` char(20) DEFAULT 'None',
  `feed_unit` char(3) DEFAULT NULL,
  `feed_multiplier` int(10) DEFAULT '100',
  `feed_timestamp` tinyint(1) DEFAULT '0',
  `feed_precision` int(11) NOT NULL DEFAULT '1',
  `feed_primary` tinyint(1) NOT NULL DEFAULT '1',
  `feed_secondary` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;

 

You'll also need the GLCDcontrol module within emonCMS (attached).

At the GLCD end you'll need to upload the attached sketch (based on the standard home energy monitor)

 

Finally, you'll need to mod raspberrypi_run.php and add the following (full file attached):

near the beginning

include "Modules/GLCDcontrol/GLCDcontrol_model.php";
  $GLCDcontrol = new GLCDcontrol($mysqli);

where it starts handling RF data its received

echo "DATA RX:".$data;
         
          $values = explode(' ',$data);
          if (isset($values[1]) && is_numeric($values[1]))
          {
        $nodeid = (int) $values[1];
   
     if (chr($values[2]) == "T" && chr($values[3]) == "X")           // emonbase Request ident
     {
      // TX request received
    $strToSend = $GLCDcontrol->respond($nodeid, $values[4], $feed, intval($values[5]));
//   echo $strToSend . "\n";
    fprintf($f,$strToSend . ",00s");
          usleep(1000); 
   
    } else {              // This bit handles normal RF receipt

 

After the control packet sending section

// Send current feed update
      if ($GLCDcontrol->sendingFeeds && ((time()-$GLCDcontrol->lastFeed) > $GLCDcontrol->feedInterval))
      {

        $GLCDcontrol->lastFeed = time();
  $feedArray = $GLCDcontrol->feedNodeArray;

  for ($i=0; $i<count($feedArray); $i++) {
   echo "Sending feed to node " . $feedArray[$i] . "\n";
   foreach ($GLCDcontrol->feedId[$feedArray[$i]] as $primary => $feedId) {
    if ($feedId != 0) {
     $str = $GLCDcontrol->sendFeedValue($feedArray[$i], $feed, $primary);
//    echo $str . "\n";
           fprintf($f,$str.",s");
           usleep(100);
    }
   }
  }
       }

 

 

Any comments and feed back welcome!

glyn.hudson's picture

Re: GLCD Control module for emonCMS

Wow! This sounds pretty cool. Trystan is away on holiday this week. I shall point him at this when he get's back. Maybe we can get it up on the emoncms modules github on the development branch so other can contribute easily

mdbigg's picture

Re: GLCD Control module for emonCMS

To do:

  1. Tidy up the front end
  2. Sort out handling of kWhd feeds (these break it at the moment...)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.