Left for archival purposes.

User avatar
By Overcrash
#19473 Is it possible to add an option to read french teleinfo serial datas ?
i'm not developper so i have not successfully get datas and pulled to LUA.
the french teleinfo is simple uart with these parameters :

speed 1200
8 bits but only 7 data bits
no parity
1 stop bit

LUA can't easy manipulate bytes, so i've try to modify the NodeMCU Firmware.

I'm able to display the correct datas with these lines added to /app/modules/uart.c :

Code: Select allbool uart_on_data_cb(const char *buf, size_t len){
  if(!buf || len==0)
    return false;
  if(uart_receive_rf == LUA_NOREF)
    return false;
  if(!gL)
    return false;
  lua_rawgeti(gL, LUA_REGISTRYINDEX, uart_receive_rf);

  [color=#0040FF]char *char_teleinfo;
  int charpos;
  while (charpos<len)
     {
     c_printf("%c", buf[charpos]&0x7f);
     charpos++;
     }[/color]

  lua_pushlstring(gL, buf, len);

  lua_call(gL, 1, 0);
  return !run_input;
}


but i'm unable to pull this to LUA...
I just want to migrate from a big arduino to a small powerful ESP8266...
the arduino code is like this :

Code: Select all#include <SoftwareSerial.h>


#define startFrame 0x02
#define endFrame 0x03

SoftwareSerial* cptSerial;

void setup()
{
  Serial.begin(9600);
 
  cptSerial = new SoftwareSerial(8, 9);
  cptSerial->begin(1200);
  Serial.println(F("setup complete"));
}

void loop()
{
  char charIn = 0;

  while (charIn != startFrame)
  {
    charIn = cptSerial->read() & 0x7F;
  }
 
  while (charIn != endFrame)
  {
    if (cptSerial->available())
    {
      charIn = cptSerial->read() & 0x7F;
      Serial.print(charIn);
    }
  }
 
  Serial.println("");
}



I've created an teleinfo emulator based on arduino :
change Serial interface as you need or convert with SoftwareSerial :

Code: Select allvoid setup() {
  Serial1.begin(1200,SERIAL_7E1);
}

void loop() {
  Serial1.print((char) 0x02);
  Serial1.print( (char) 0x0A);
  Serial1.print("ADCO 012345678901 F");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("OPTARIF HC.. <");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("ISOUSC 20 8");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("HCHC 036424518 '");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("HCHP 026582379 =");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("PTEC HP..  ");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("IINST1 003 K");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("IINST2 000 I");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("IINST3 001 K");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("IMAX1 019 :");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("IMAX2 020 3");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("IMAX3 018 ;");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("PMAX 08380 9");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("PAPP 00970 1");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("HHPHC E 0");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("MOTDETAT 000000 B");
  Serial1.print( (char) 0x0D);
  Serial1.print( (char) 0x0A);
  Serial1.print("PPOT 00 #");
  Serial1.print( (char) 0x0D);
  Serial1.print((char) 0x03);
}


Regards
User avatar
By TerryE
#19482 Before you start trying to develop custom libraries, just make sure that you don't "reinvent the wheel". The bit library give you bit manipulation in Lua. Unfortunately, the SDK and therefore Lua only support 9600 minimum, but there are other example S/W implementations of a serial driver on the forums.
User avatar
By Overcrash
#19484
TerryE wrote:Before you start trying to develop custom libraries, just make sure that you don't "reinvent the wheel". The bit library give you bit manipulation in Lua. Unfortunately, the SDK and therefore Lua only support 9600 minimum, but there are other example S/W implementations of a serial driver on the forums.


I'm sorry but i've successful get the correct datas with my c_printf, so NodeMCU support 1200bauds. :D
I just search atm how to put my c_printf to LUA with lua_pushlstring() func

I tried to use the bit library, but i'm unable to do anything... but i'm not a developer