ESP8266 Webserver Project

Moderator: Sprite_tm

User avatar
By dnts
#6925
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):

Code: Select allstatic 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
User avatar
By bkrajendra
#6962 Thanks dnts. :D

But I figured it out similar way before I see ur reply.
I've written a function sendHex in stdout.c

Code: Select allvoid sendHex(unsigned int 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);
}



then included stdout.h in user_main.c... I dnt know now how to do it in a proper way.
Like using it like a os_printf function directly. There can be a new function os_printfHex().

Currently I'm just trying to understand the code and structure of code.
And finally my dimmer worked like charm!!!
https://www.youtube.com/watch?v=VqVtMilrtZg

But this dimmer module is ready made, which needs just serial hex to dim it.
Can you just guide me how to use ESP pwm function and interrupt to implement native dimming using ESP itself.
I tried this with MOC3021 and 4N35-ZCD, but had no success. Dimmer works but ESP interfacing ds not work.
Let me know if know some way to do this..!!!


Thank you all friends.
User avatar
By dnts
#7021
Sprite_tm wrote:kasperfish: Bedankt :)

dnts: What SDK do you use? I can't really find a reference to WIFI_CLIENTSSID anywhere, and at least with the 0.9.4 SDK I have no trouble.


Hi Sprite_tm.
Look up this code:
Code: Select allvoid setup_wifi_st_mode(void)
{
   wifi_set_opmode((wifi_get_opmode()|STATION_MODE)&STATIONAP_MODE);
   struct station_config stconfig;
   wifi_station_disconnect();
   wifi_station_dhcpc_stop();
   if(wifi_station_get_config(&stconfig))
   {
      memset(stconfig.ssid, 0, sizeof(stconfig.ssid));
      memset(stconfig.password, 0, sizeof(stconfig.password));
      //os_sprintf(stconfig.ssid, "%s", WIFI_CLIENTSSID);
      //os_sprintf(stconfig.password, "%s", WIFI_CLIENTPASSWORD);
      os_printf("\nCopying SSID/PWD ;default settings\n");
      /*if(!wifi_station_set_config(&stconfig))
      {
         #ifdef PLATFORM_DEBUG
         os_printf("ESP8266 not set station config!\r\n");
         #endif
      }*/
   }

in WIFI.c.
The WIFI_CLIENTSSID is in user_config.h in the INCLUDE dir.

While we are at it.. is there any field holding the connection destination IP - I need to tell if the current access comes through the AP or STA so I can differentiate between configuration access (via AP) and standard access (via STA). I tried to use
Code: Select allconnData->conn->proto.tcp->local_ip[0..3]
but it's all 0 even with connection coming in. Any other idea?
Nir