bkrajendra wrote:Hello @Sprite_tm
I'm trying to implement AC dimmer wth ESP code.
My dimmer hardware requires serial hex data for dimming.
for ex. 0x00 will switch it off and 0xFF will make it glow high.
I'm giving this data through range selector in HTML5. = 0 to 255.
Cgi code for it as follows.Code: Select all//Transmit Serial Data
int ICACHE_FLASH_ATTR SendSerialData(HttpdConnData *connData) {
int len;
char buff[1024];
char dataTX[1024];
httpdStartResponse(connData, 200);
httpdHeader(connData, "Content-Type", "text/json");
httpdEndHeaders(connData);
if (connData->conn==NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
httpdFindArg(connData->postBuff, "dataTX", dataTX, sizeof(dataTX));
len=os_sprintf(buff, "{\n \"result\": { \n\"data\": \"%s\"\n }\n}\n",dataTX);
os_printf("%s",dataTX); // This is sending data to my AC dimmer Hardware
//len=os_sprintf(buff, "]\n}\n}\n");
espconn_sent(connData->conn, (uint8 *)buff, len);
return HTTPD_CGI_DONE;
}
now the problem is when HTML range selector sends 23 my serial terminal screen shows it as 23 but I think actual data sent is
"32 33"
What can be done to send only single hex value from 00 to FF serial.
Please help!!!
If you ask printf to send a number formatted as string (os_printf("%s",dataTX)) it will convert if to ASCII number (32 is '2' and 33 is '3'). What you want to do is send a single HEX digit directly to the UART since printf and event PUTC will reformat some of the values as they treat the input as CHAR rather than uint8. You can use this (stole this from somewhere else in the code):
static void ICACHE_FLASH_ATTR UartTxd(char c) {
//Wait until there is room in the FIFO
while (((READ_PERI_REG(UART_STATUS(0))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT)>=126) ;
//Send the character
WRITE_PERI_REG(UART_FIFO(0), c);
}
This will transmit a single byte over the UART.
Nir