Skip to main content
jendoubi saif ddine
Associate II
Apr 20, 2018 10:08 PM UTC
Solved

Sprintf effect on Send_text LwIP is going wrong

Posted on April 21, 2018 at 00:08

so this is my function that works fine when i add it to the script :

  • send_text(pAcceptedConnection, ' function drawChart() {var data = new google.visualization.DataTable();data.addColumn('string', 'Topping');data.addColumn('number', 'Slices');data.addRows([['Mushrooms', 3],['Onions', 2],['Olives', 1],['Zucchini', 4],['Pepperoni', 2]]);var options = {'title':'How Much Pizza I Ate Last Night','width':400,'height':300};var chart = new google.visualization.PieChart(document.getElementById('chart_div'));chart.draw(data, options);}');

but once i pass the inside message on Sprintf to make once of the values taken from a variable and do the same thing again like this : 

  • sprintf((char*) msggg1,' function drawChart() {var data = new google.visualization.DataTable();data.addColumn('string', 'Topping');data.addColumn('number', 'Slices');data.addRows([['Mushrooms', 3],['Onions', 2],['Olives', 1],['Zucchini', 4],['Pepperoni', %d]]);var options = {'title':'How Much Pizza I Ate Last Night','width':400,'height':300};var chart = new google.visualization.PieChart(document.getElementById('chart_div'));chart.draw(data, options);}',x);

    send_text(pAcceptedConnection,(const char*)msggg1);

it won't work 

this is the send function :

  1. static void

    send_text(struct netconn *conn, const char *text)

    {

    const char *src = text;

    u16_t len = 0;

    while (*src++ != '\0')

    len++;

    netconn_write(conn, text, len, NETCONN_COPY);

    }

if anyone can help please and thanks 

#lwip #stm32f7
This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Apr 20, 2018 10:40 PM UTC
Posted on April 21, 2018 at 00:40

Make sure your msggg1 character array is allocated with sufficient space behind it to hold the data you are generating.

sprintf() returns the string length

So smarter implementation looks like

netconn_write(pAcceptedConnection, msggg1, sprintf(msggg1,'..',..), NETCONN_COPY);

sscanf/sprintf may also have stack utilization, check it is sufficient

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..

3 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Apr 20, 2018 10:40 PM UTC
Posted on April 21, 2018 at 00:40

Make sure your msggg1 character array is allocated with sufficient space behind it to hold the data you are generating.

sprintf() returns the string length

So smarter implementation looks like

netconn_write(pAcceptedConnection, msggg1, sprintf(msggg1,'..',..), NETCONN_COPY);

sscanf/sprintf may also have stack utilization, check it is sufficient

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
jendoubi saif ddine
Associate II
Apr 21, 2018 12:58 AM UTC
Posted on April 21, 2018 at 00:58

Thanks for responding as usual sir, 

sadly that didn't work .. i even tryed to change sending function but it didn't work