Skip to main content
jendoubi saif ddine
Associate II
April 20, 2018
Solved

Sprintf effect on Send_text LwIP is going wrong

  • April 20, 2018
  • 3 replies
  • 1061 views
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.
Best answer by Tesla DeLorean
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

3 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
April 20, 2018
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
April 21, 2018
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