the problem of data format

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
livebelive
Normal user
Posts: 13
Joined: 08 May 2017, 22:50

the problem of data format

#1 Post by livebelive » 10 May 2017, 06:04

I modified a plug-in to read serial data, and then sent to the domoticz, but encountered a display problem.
Following figure!
12345.png
I only call and display a value.
But in domoticz, the data becomes 1; 0; 0, three value!
23456.png
I guess the other two groups should be TEM and u in the original plug-in
How to delete the following two value
You do not have the required permissions to view the files attached to this post.

livebelive
Normal user
Posts: 13
Joined: 08 May 2017, 22:50

Re: the problem of data format

#2 Post by livebelive » 10 May 2017, 06:06

Code: Select all

/*

  This plug in is written by Dmitry (rel22 ___ inbox.ru)
  Plugin is based upon SenseAir plugin by Daniel Tedenljung info__AT__tedenljungconsulting.com
  Additional features based on https://geektimes.ru/post/285572/ by Gerben (infernix__AT__gmail.com)

  This plugin reads the CO2 value from MH-Z19 NDIR Sensor
  DevicePin1 - is RX for ESP
  DevicePin2 - is TX for ESP
*/


#define PLUGIN_049
#define PLUGIN_ID_049         49
#define PLUGIN_NAME_049       "Voice Siri"
#define PLUGIN_VALUENAME1_049 "Voice Data"
#define PLUGIN_READ_TIMEOUT   3000

boolean Plugin_049_init = false;
byte ppm;
#include <SoftwareSerial.h>
SoftwareSerial *Plugin_049_SoftSerial;

// 9-bytes CMD PPM read command
byte mhzCmdReadPPM[1] = {0xFF};

boolean Plugin_049(byte function, struct EventStruct *event, String& string)
{
  bool success = false;

  switch (function)
  {

    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_049;
        Device[deviceCount].Type = DEVICE_TYPE_DUAL;
        Device[deviceCount].VType = SENSOR_TYPE_TRIPLE;
        Device[deviceCount].Ports = 0;
        Device[deviceCount].PullUpOption = false;
        Device[deviceCount].InverseLogicOption = false;
        Device[deviceCount].FormulaOption = true;
        Device[deviceCount].ValueCount = 1;
        Device[deviceCount].SendDataOption = true;
        Device[deviceCount].TimerOption = true;
        Device[deviceCount].GlobalSyncOption = true;
        break;
      }

    case PLUGIN_GET_DEVICENAME:
      {
        string = F(PLUGIN_NAME_049);
        break;
      }

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_049));
        break;
      }

    case PLUGIN_INIT:
      {
        Plugin_049_SoftSerial = new SoftwareSerial(Settings.TaskDevicePin1[event->TaskIndex], Settings.TaskDevicePin2[event->TaskIndex]);
        Plugin_049_SoftSerial->begin(115200);
        addLog(LOG_LEVEL_INFO, F("Voice Siri: Init OK "));

        //delay first read, because hardware needs to initialize on cold boot
        //otherwise we get a weird value or read error
        timerSensor[event->TaskIndex] = millis() + 15000;

        Plugin_049_init = true;
        success = true;
        break;
      }


    case PLUGIN_READ:
  {

        if (Plugin_049_init)
        {

      if (Plugin_049_SoftSerial->available() > 0) {
      ppm = Plugin_049_SoftSerial->read();
      UserVar[event->BaseVarIndex] = (unsigned int)ppm;
      String log = F("Voice Data: : ");
      log += (int)ppm;
      addLog(LOG_LEVEL_INFO, log);
      } else {
      delay(10);
      }
      success = true;
      break;
        }
        
    break;
  }

  }
  return success;
}
This is the plug-in code

livebelive
Normal user
Posts: 13
Joined: 08 May 2017, 22:50

Re: the problem of data format

#3 Post by livebelive » 10 May 2017, 06:32

The problem has been solved!!!
Device[deviceCount].VType = SENSOR_TYPE_TRIPLE; this place needs to be replaced
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: the problem of data format

#4 Post by toffel969 » 10 May 2017, 10:02

livebelive wrote: 10 May 2017, 06:32 The problem has been solved!!!
Device[deviceCount].VType = SENSOR_TYPE_TRIPLE; this place needs to be replaced
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
very good ! Glad to hear you were succesful !
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

livebelive
Normal user
Posts: 13
Joined: 08 May 2017, 22:50

Re: the problem of data format

#5 Post by livebelive » 10 May 2017, 15:30

thank you again!

livebelive
Normal user
Posts: 13
Joined: 08 May 2017, 22:50

Re: the problem of data format

#6 Post by livebelive » 10 May 2017, 16:13

if (Plugin_049_init)
{
byte ppn[1];
ppn[1] = 1;
if (Plugin_049_SoftSerial->available() > 1) {
ppm = Plugin_049_SoftSerial->read();
UserVar[event->BaseVarIndex] = (unsigned int)ppm;
Plugin_049_SoftSerial->write(ppn[1]);
UserVar[event->BaseVarIndex] = (unsigned int)ppm;
String log = F("Voice Data: : ");
log += (int)ppm;
addLog(LOG_LEVEL_INFO, log);
} else {
delay(10);
}
success = true;
break;
}
The new problem, I changed a good plug-in, now there is a small problem, he will be sent to domoticz seconds every time, I want him to read the data, only to send domoticz once again to read data and send again, do not repeat sending.
I do not know whether it is because the serial port data has not been emptied, repeated execution of the variable ppm, or because the system is sent to the default delay parameters.
Or I would like to know what the specific format is sent directly to the code in the following instructions to send, no longer call the system to send the data sent to the specified idx.

Martinus

Re: the problem of data format

#7 Post by Martinus » 10 May 2017, 20:33

Your code should not return true when no reading has been performed (serial input received in your scenario), i think you'd have to rewrite it like this:

Code: Select all

  case PLUGIN_READ:
  {
    if (Plugin_049_init)
    {
      if (Plugin_049_SoftSerial->available() > 0)
      {
        ppm = Plugin_049_SoftSerial->read();
        UserVar[event->BaseVarIndex] = (unsigned int)ppm;
        String log = F("Voice Data: : ");
        log += (int)ppm;
        addLog(LOG_LEVEL_INFO, log);
        success = true;
      }
      else
      {
        delay(10);
      }
    }
    break;
  }

Who is online

Users browsing this forum: Anthropic Claude Bot [bot] and 12 guests