Tiny WebServer code

@tomas

This is just some ideas from a novice coder that you probably already know but, I would still like to mention it here as others may not know about it. PHP include statements from .php files can parse html to the browser from a server side file so my idea is to put the very minimal code needed to control the core utilizing BDub’s Tiny Web Server and then use an iframe. So no HTML is needed in the IDE code. So basically you have the Core say to the browser, “Hi I am Sparky, now let me shine” :smile:

It all works very well and you can have multiple iframe statements to section off the browser page with different inclusions from different output from the core or from different sources on the web.

The only thing I need to do is to figure out how to move the Core Token and ID numbers to an external file and then include them back as a variable in to my index.html to make it more secure.

Is this scheme the best approach ? (I’m not sure)

Update;

@zach (I believe in another topic) let me know that I only need to secure the Token No.

And what I meant best approach, I was referring to using HTML/PHP outside the core to maximize core usable coding space.

spydrop, from reading the forum I think there a need for both solutions. What is needed is a solid example for each of these approaches. Much like tinker, these would provide a good foundation for new members. :smile:

Yup! You'll be able to make POST and GET requests and handle different pages, and serve up javascript, images, etc..

3 Likes

A JSON library comes to mind. It’s a little redundant with the web API, but I could see a valid use for it on some sort of secure internal network where you may not want to expose anything via the web API. It may also give you access to more network-available variables and/or functions.

@BDub any update on how the websever port is coming along, with the flash library now ported I am rather keen to see this in action :smiley:

I had it displaying a test page, but I had some issues with it not closing the socket last I looked at it. I’ve just been busy but will get back on finishing it up asap. Thanks for hanging in there :wink:

1 Like

Hi,

Im trying to host a webpage on my core too can you explain how you made the page in your code from the picture?

@mstelt, He made the HTML code in the serveWebPage() function in @BDub’s post above. You can safely strip out the LquidCrystal and lcd stuff.

The actual HTML code printed in serveWebpage() looks like this to your browser:

<html><body>BDub's Server Uptime: 12345 seconds</body></html>

There are a few day-job web developers here in the forums that can help you with the HTML code. It may be better to start a separate thread for it, but we’d be happy to help!

1 Like

@mstelt,

Hi Marco,

You can use a lot of html and some php or java in the IDE but its trial by error. One thing to do is place a forward slash in before any " mark (quotation mark) or where possible use an ’ (appostirphy) in the html/java/php code.

You can also link external pages such as *.css / *.js / *.php

Let me know if you need example code to start from.

Bobby

@spydrop,

i see a familiar name popping by :smiley:

Hi Kenneth, @kennethlimcp

It would nice for Marco and others (Like ME - Please !) :slight_smile: to be able to run Tiny Webserver on one of you SD/Fram cards ! can’t wait.

Are you doing to make your Eagle files open source ? I’d immediately order them from OSHPark.com and ship them to you

Bobby

1 Like

It will be open source and i’m working with Will and Mohit to get the files prepared for production! :smiley:

3 Likes

@kennethlimcp, Yes ! You are more than awesome !

Production ! ---- Can it be a Kickstarter Campaign ? Where do I send money !

1 Like

Thanks @spydrop!

Been busy with school but you will be the 1st to hear or even receive once i launch :smiley:

3 Likes

Thanks @kennethlimcp !!

1 Like

Hi,

I got it all running wiht replacing the " for ’ and putting all the code in a single line. I can split it up but my Core is having some problems with the busyness in my WiFi(not the most pretty code I wrote but ow well xd) but I want to add the .html page to the project besides the .ino file.Is there a way to do this in the Builder because I couldn’t find it.

Marco

I'm not sure that it's possible to do something like that. The Core doesn't have a "disk" per se, so you couldn't simply ask it to load something like index.html from a disk or flash. It is possible that you could create .cpp (or should it be .h?) files that are page-specific to help you organize. Something like this might work:

index.cpp

String index_html = "<html><body> Blah blah blah </body></html>";

pagetwo.cpp

String pagetwo_html = "<html><body>This is another page</body></html>";

It's probably not the prettiest solution, but it would help to keep things organized.

I would make those HTML sections global static char arrays so that they can be entirely in flash rather than use up RAM for them assuming they never change.

static char index_html[] = "<html><body>...";
1 Like

Hmm that a really good idea actually. Can you give me some more info on how to set it up?

Sorry, my html skills are very poor :frowning:

On the core, were you had

  webClient.print("<html><body>BDub's Server Uptime: ");
  webClient.print(millis()/1000);
  webClient.println(" seconds</body></html>\n\n");

You would write

//global
static const char index_part1[] = "<html><body>BDub's Server Uptime: ...LOTS MORE HERE";
static const char index_part2[] = { "... LOTS MORE HERE TOO seconds</body></html>", '\n','\n','\0'};

  webClient.print(index_part1);
  webClient.print(millis()/1000);
  webClient.println(index_part2);

You have to figure out what you want to say on the embedded web page.

1 Like