Go Down

Topic: Change a .txt content online (Read 633 times) previous topic - next topic

iouzzr

Hi there, I'm new to here and have some questions:
I am using MEGA 2560 and Ethernet shield to control some relays. There are some status stored in SD card, such as IP and MAC, and relays' status, like below:
ip = 192.168.1.129
mac = 00-4A-E5-8B-0D-6D
baud = 19200
R1,P,T1000
R2,P,T1000
R3,P,T1000
R4,P,T1000
R5,P,T1000
R6,P,T1000
R7,P,T1000
R8,P,T1000
G1,1-2,T1000-500
G2,1-2-3,T1000-500-1000
G3,1-2-3-4,T1000-500-1000-500
G4,1-2-3-4-5,T1000-500-1000-500-1000
G5,1-2-3-4-5-6-7-8,T1000-900-800-700-600-500-400-300

The question is: I need to change the configs.txt online.
My solution is: print the current configs.txt on browser in textarea. If you want to change the configs, you just modify the text content, and then press "SUBMIT", Arduino will save the new configs in buffer, delete the previous one, and create a new configs.txt according to the buffer. But it seems dificult to use "method=GET" to handle it, the URL cannot hold too many strings! For "method=POST", I am not sure whether it will work.
So can anybody help me to POST or do you have other better opinions? Thanks a lot!

rockwallaby

Yes, the POST method would be the correct way to do this.
How are you working with http transactions now, what libraries are you using?

If you use something like the Webduino library, I believe it could make it easier for you, plus you will have the possibility to have authorisation.
If your interested, look here https://github.com/sirleech/Webduino

iouzzr

#2
Feb 21, 2013, 08:32 am Last Edit: Feb 21, 2013, 09:12 am by iouzzr Reason: 1

Yes, the POST method would be the correct way to do this.
How are you working with http transactions now, what libraries are you using?

If you use something like the Webduino library, I believe it could make it easier for you, plus you will have the possibility to have authorisation.
If your interested, look here https://github.com/sirleech/Webduino


Thanks, rockwall!
Actually I'm not using any http transactions, instead, I just using code like:

if (strstr(clientline, "GET /relay_write") != 0) {
...
}

For example, when URL is "192.168.1.129/relay_write?id=2", I will operate No.2 relay.
I looked into Webduino.h to see how it parse "POST", but i am confused. Actually I dont know where the value comes to. For "GET" I know, the value "id=2" comes in URL. But for "POST", I dont know.

iouzzr

Problem solved! "GET" is OK to handle this, though I still dont know how to use "POST"...

Go Up