Transfer simple server to wordpress

Hello,

I have perfected my simple server using arduino, and would like to add it to my website. I figured out how to transfer the code itself to wordpress so the homepage loads correctly, but I can't figure out how do the

if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then

this is important because I need to use

// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
digitalWrite(9, HIGH); // GET /H turns the LED on
}

so I can make the server do different things. I would prefer to be able to read everything sent to the server when the server is a computer, like I can read everything in the ethernet client example, but I can't figure out how to do that on a computer. I spent many many hours on Google trying to figure out how to do this.
Does anyone know how to do this? Preferably using linux.

Very confusing. Is an arduino acting as a web server? Why is wordpress mentioned? Then server being a computer, why is an arduino related to this if a computer is a server?

Very confusing. Is an arduino acting as a web server? Why is wordpress mentioned? Then server being a computer, why is an arduino related to this if a computer is a server?

I used arduino to write the server code, and test it. I can not seem to get a device that is not connect to the same internet modum as the arduino to see the server site though.

I bought a web domain and installed wordpress to try to fix this problem. Wordpress was the recommended website developer tool. I am trying to transfer the arduino server code to wordpress so people that are not connected to the same internet modem as the arduino can see the site I built.

I was able to transfer the code that shows the server page, but can't figure out how to do this

if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then

So i can see the information sent to the wordpress server. I need to be able to see it so I can do

// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
digitalWrite(9, HIGH); // GET /H turns the LED on
}[/quote on the server, so it can have the same capabilities as the arduino.

OK, you have arduino acting as a server on your local network. It blinks LED on request. Now you want to have people on the internet to blink your LED by visiting the domain. I thought all you had to do is to get dynamic DNS service and install it on your home router. Then your router will be updating its IP address to the DDNS server and anyone visiting your domain name will be told your router's IP address. You also need to set up tunneling on your router to allow internet computers send requests to your arduino. Am I completely misunderstanding you?

Thomas499:
I was able to transfer the code that shows the server page, but can't figure out how to do this

This sounds like you are trying to get an Arduino program to work on a Wordpress website. It won't happen.

...R

I thought all you had to do is to get dynamic DNS service and install it on your home router. Then your router will be updating its IP address to the DDNS server and anyone visiting your domain name will be told your router's IP address. You also need to set up tunneling on your router to allow internet computers send requests to your arduino. Am I completely misunderstanding you?

Well that's one way to do it, but I was hoping for more of a client based code for the arduino. The arduino pings the webaddress like it does with the ethernet client example, the website recieves the ping, and instead of sending the "arduino google search" information to the arduino, it sends the information that tells it to turn on or off the led.... would that not work?

This sounds like you are trying to get an Arduino program to work on a Wordpress website. It won't happen.

not work on a wordpress website... more like with a wordpress website, i was thinking the arduino would be the client, and the wordpress would be the universal server.... is that not feasible?

Thomas499:
wordpress would be the universal server.... is that not feasible?

That should be feasible but I was confused by your title which refers to "transfer to wordpress"

If you are trying to use client.available() etc to read data from wordpress you may be interested in the examples in Serial Input Basics which could easily be adapted to work with client rather than Serial.

...R

If you are trying to use client.available() etc to read data from wordpress

actually I want the wordpress site to be able to read the data sent by other users.

Heres an example. This currently works on the arduino, but I am trying to transfer the logic to the wordpress server. It displays which leds are on and off.

if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("led 1 is ");
            if (led1==high)
            client.print("on");
            else
            client.print("off");
            client.print("
");
            client.print("led 2 is ");
            if (led2==high)
            client.print("on");
            else
            client.print("off");
            client.print("
");
            client.print("led 3 is ");
            if (led3==high)
            client.print("on");
            else
            client.print("off");
            client.print("
");
            client.print("Click <a href=\"/H1\">here</a> turn the LED on pin 9 on
");
            client.print("Click <a href=\"/L1\">here</a> turn the LED on pin 9 off
");
            client.print("Click <a href=\"/H2\">here</a> turn the LED on pin 9 on
");
            client.print("Click <a href=\"/L2\">here</a> turn the LED on pin 9 off
");
            client.print("Click <a href=\"/H3\">here</a> turn the LED on pin 9 on
");
            client.print("Click <a href=\"/L3\">here</a> turn the LED on pin 9 off
");
            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          } else {    // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
        if (currentLine.endsWith("GET /H1")) {
          led1=HIGH;               // GET /H1 stores boolean led1 high so that information is created and printed afterwards
        }
        if (currentLine.endsWith("GET /L1")) {
          led1=LOW;                // GET /L1 stores boolean led1 low so that information is created and printed afterwards
        }
        if (currentLine.endsWith("GET /H2")) {
          led2=HIGH;               
        }
        if (currentLine.endsWith("GET /L2")) {
          led2=LOW;                
        }
        if (currentLine.endsWith("GET /H3")) {
          led3=HIGH;               
        }
        if (currentLine.endsWith("GET /L3")) {
          led3=LOW;                
        }

I figured out how to write pages on wordpress, but I don’t want to write a page for every possible varible. For example, I don’t want to have to do this

page1
led1=on
led2=off
led3=off

page2
led1=on
led2=on
led3=off

instead I want to use the booleans to write the page like I do in the arduino sketch. To do this, i need to be able to do something similar to this in wordpress

if (client.available()) { // if there’s bytes to read from the client,
char c = client.read(); // read a byte, then

so that I can see what the client sent to the server so I can do this on the wordpress site

// Check to see if the client request was “GET /H1” or “GET /L1”:
if (currentLine.endsWith(“GET /H1”)) {
led1=HIGH; // store as boolean so wordpress site knows what to write, eliminating the need for a special page written in advance for every possible outcome.
}

Thomas499:
actually I want the wordpress site to be able to read the data sent by other users.

Slow down a bit please. Forget about code for a few minutes.

Just give us a description in plain language (no code) of what the whole project is supposed to do - ideally with some examples of the data.

...R

I want to access the same information on wordpress that is printed to the serial monitor on the client example.

I want to figure out how to get this using wordpress (on the wordpress side, not the arduino side)

new client
GET /H1led1 is now on
 HTTP/1.1
Host: 192.168.1.21
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://192.168.0.21/H1
Connection: keep-alive

I have 10 relays. Each controls something different, some take temp readings. I want to view this information, and be able to control the arduino using wordpress. I don't want to have to write a page for each possible variable change, so I would like for the wordpress page display page to be dependent on booleans. To change the booleans I need to be able to get to get and parse from the information sent to the server, preferably in a similar way to how you do with arduino.

Does that make since? The arduino sends information as a client to wordpress

User-Agent: arduino1:
led1 is off
led2 is on
Temp is: 89
Any new commands?

Server then saves the information: temp is 89, led1 is off, led2 is on.
User accesses wordpress website. clicks on button to turn led1 on
Wordpress receives informaiton

User-Agent: computer
turn led1 on

wordpress response as a server to user
basically displays the information

Hello computer:
led1 is on
led2 is off
led3 is off
temp is 89

Arduino client request informaiton

User-Agent: arduino1:
Temp is: 89
Any new commands?

wordpress response as a server to arduino

Hello arduino1:
I saved these instructions for you while I waited to hear from you
turn led1 on
turn led3 off
these instructions were sent by a user not connected to the same modem you are connected to

I'm not 100% following you..

but I think you need a 3rd party (man-in-the-middle) helper here..

IMHO...

you would have the Arduino poll a DATABASE, so you can store these values in a table (how often it updates is up to you and your project needs)..and use them in your Arduino code/behavior

they stay there so you can then retrieve them from a webpage. (let take "Wordpress" out of the equation.. but really,.. its irrelevant)... wordpress, blog, website.. in this scenario its really all the same (more or less)

on your webpage.. you have some code/app that queries this database, gets the data for each and every sensor you have logged in there (name and state of sensor perhaps?)

and displays this information on the page.

If you want to be able to CONTROL these sensors/relays from the web page.. then you'll have to also write in some controls checkboxes/radio buttons (whatever you need).. so that when you set these control and hit SUBMIT on the webpage.. the database updates with these new values.

really there are a lot of ways you can tweak this.. and this might not be the BEST approach (nor the only one by any means)... perhaps a table/column that saves the sent behavior from the page.. and another column/table that the Arduino can update to give it current state of things...etc

but I think you need a 3rd party (man-in-the-middle) helper here..

IMHO...

you would have the Arduino poll a DATABASE

Yes, please don't crucify me for referencing a pi example, but the purpose is to intergrate the proof of concept wordpress server using the pi to work with the arduino before I purchase an domain name. When I was following the LAMP example LAMP (Linux, Apache, MySQL, PHP) example for the pi I thought the whole point of going over the MySQL stuff was to get you ready to use it in wordpress.... MySQL is a database correct? I'm not a fan of the documentation regarding proper clear instructions when using the pi, but the Tre never came around and I got tired of waiting.

on your webpage.. you have some code/app that queries this database, gets the data for each and every sensor you have logged in there (name and state of sensor perhaps?)

and displays this information on the page.

Perfect translation! Pretty much sums up what i'm trying to do!

If you want to be able to CONTROL these sensors/relays from the web page.. then you'll have to also write in some controls checkboxes/radio buttons (whatever you need).. so that when you set these control and hit SUBMIT on the webpage.. the database updates with these new values.

The buttons are easy to write, it's just most of the examples on the internet that deal with the buttons taking the user to a page, and the page needs to be set up in advance. That method would require this format

page1

led1-off
led2-off
led3-off

page2

led1-on
led2-off
led3-off

I don't want to write a ton of pages for every possibility, so instead I need a way to use assign booleans that determine what is written on the page... to do that I need to find the way to do the

while client available client read if currentLine ends with

stuff on a linux computer, or on wordpress. That's what i'm trying to figure out, how to pull that information like you do with the arduino server. Is there a universal client.read() command?

really there are a lot of ways you can tweak this.. and this might not be the BEST approach (nor the only one by any means)... perhaps a table/column that saves the sent behavior from the page.. and another column/table that the Arduino can update to give it current state of things...etc

any tutorial, or recommendation approach would be much appreciated. I'm a complete newb, anyone that has experience in this that can lead me in a recommended direction would be very much appreciated. I was just under the impression from the lamp example that was the next step

Thomas499:

  • The arduino sends information as a client to wordpress
  • Server then saves the information: temp is 89, led1 is off, led2 is on.
  • User accesses wordpress website. clicks on button to turn led1 on
  • Wordpress receives informaiton
  • wordpress response as a server to user
  • basically displays the informationArduino client request informaitonwordpress response as a server to arduino

I have taken a piece of your Reply #11 and just re-formatted.

What you have here is perfectly practical. But Wordpress cannot “send” a request to the Arduino. The Arduino (client) has to send to Wordpress. Just arrange for the Arduino to send data regularly. Then when a user contacts Wordpress it can give him (or her) the latest data from the Arduino.

If necessary, the Arduino could “ask” Wordpress what data is required and then respond with the appropriate values. This can also be used if you want the Arduino to act on data in Wordpress - such as to turn on a relay.

You may find some ideas in this EzScrn demo - but it is designed to work with your own server on the PC rather than with Wordpress.

There is a technique called “long polling” (Google it) which gives the user the impression of instant (or very fast) interaction between a server and a client. The client makes a request (a poll) but the server does not respond until it has some reason to - perhaps after receiving data from another client.

…R

u may find some ideas in this EzScrn demo - but it is designed to work with your own server on the PC rather than with Wordpress.

Is there anyway you can tell me which folder or at least which keyword to look for that shows..... Well I want to print everything that comes in on the server side (on the python program) I don't know what i'm looking for to get it to do that and there are so many folders.

There is a technique called "long polling" (Google it) which gives the user the impression of instant (or very fast) interaction between a server and a client.

I found where you use it in the function sendDataTo Browser(); this is very interesting!

xl97 mentioned DATABASE so I'll expand on that a bit. I've used a database from sparkfun.com under data.sparkfun.com
The server records data streams and can be queried with simple queries, such as the most recent data etc. You can set up two streams. One for your data (temperature etc.) the other for command (LED1 on/off etc.)

The wordpress page simply provides the proper link to post commands to the command stream and proper link to query status or data (or graph it if you like). Arduino side queries the command stream periodically (say every 30 seconds) to receive the most recent command and also posts its status and data.

One thing to remember is that once a client browser receives a web page from a server, the server is done and the page now exist on the client browser. There no more interaction with server unless the browser makes another request to the server(s). The downloaded web page can have request/control links for the arduino server. It is probably more practical for the web page loaded in the client browser to interact directly with the arduino supplying status info or performing control functions to the web page loaded in the browser.

zoomkat,

I don't know why OP doesn't want to do what you mentioned. I even mentioned DDNS solution. OP wants arduino to be a client so some server must cache data and commands.

It is probably more practical for the web page loaded in the client browser to interact directly with the arduino supplying status info or performing control functions to the web page loaded in the browser.

I don't know why OP doesn't want to do what you mentioned.

Because I don't own the server the webpage is hosted on. It's not in the same building as the arduino, so the arduino can not be physically connected to the server. The user interacting or controlling the webpage/arduino will probably access the page from their cell phone. The phone will not be connected directly to the arduino either.

I even mentioned DDNS solution.

I looked into your DDNS recommendation. I spent a few hours looking into it and it was a great idea. I'll explain why I do not think it is a good idea for my project. The problem is that I want to be able to take the arduino to other places to show people. With DDNS you have to mess with a whole lot of router settings, and tunneling setup. This would be very inconvenient when you want to show someone real quick your arduino and you have to go into their router and change settings. I don't know if setting a router up to allow that would open loopholes in their internet firewires, but I know I want to take this places, and I don't want to spend a hour each time settings up the settings to allow DDNS each time I take this to a new place.

Thomas499:
Is there anyway you can tell me which folder or at least which keyword to look for that shows..... Well I want to print everything that comes in on the server side (on the python program) I don't know what i'm looking for to get it to do that and there are so many folders.

I don't know if you are still interested in an answer to this.

Everything that the server receives is first received by the code in the file EzScrn03.py That program then calls other functions to do the detail work.

Have a look at the documentation for Bottle and it should be clearer.

...R