-
-
Notifications
You must be signed in to change notification settings - Fork 14
Added cgi #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Added cgi #10
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,7 @@ cmake/pico_sdk_import.cmake | |
# clangd stuff | ||
.cache | ||
compile_commands.json | ||
|
||
#kate backups | ||
*~ | ||
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
cmake_minimum_required(VERSION 3.19) | ||
cmake_minimum_required(VERSION 3.18) | ||
|
||
find_package(Perl) | ||
if(NOT PERL_FOUND) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#include "lwip/apps/httpd.h" | ||
#include "pico/cyw43_arch.h" | ||
#include "lwipopts.h" | ||
#include "cgi.h" | ||
|
||
|
||
static const tCGI cgi_handlers[] = { | ||
{ | ||
/* Html request for "/leds.cgi" will start cgi_handler_basic */ | ||
"/leds.cgi", cgi_handler_basic | ||
}, | ||
{ | ||
/* Html request for "/leds2.cgi" will start cgi_handler_extended */ | ||
"/leds_ext.cgi", cgi_handler_extended | ||
} | ||
}; | ||
|
||
|
||
|
||
/* cgi-handler triggered by a request for "/leds.cgi" */ | ||
const char * | ||
cgi_handler_basic(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) | ||
{ | ||
int i=0; | ||
|
||
/* We use this handler for one page request only: "/leds.cgi" | ||
* and it is at position 0 in the tCGI array (see above). | ||
* So iIndex should be 0. | ||
*/ | ||
printf("cgi_handler_basic called with index %d\n", iIndex); | ||
|
||
/* All leds off */ | ||
Led_Off(LED1); | ||
Led_Off(LED2); | ||
Led_Off(LED3); | ||
Led_Off(LED4); | ||
|
||
/* Check the query string. | ||
* A request to turn LED2 and LED4 on would look like: "/leds.cgi?led=2&led=4" | ||
*/ | ||
for (i = 0; i < iNumParams; i++){ | ||
/* check if parameter is "led" */ | ||
if (strcmp(pcParam[i] , "led") == 0){ | ||
/* look ar argument to find which led to turn on */ | ||
if(strcmp(pcValue[i], "1") == 0) | ||
Led_On(LED1); | ||
else if(strcmp(pcValue[i], "2") == 0) | ||
Led_On(LED2); | ||
else if(strcmp(pcValue[i], "3") == 0) | ||
Led_On(LED3); | ||
else if(strcmp(pcValue[i], "4") == 0) | ||
Led_On(LED4); | ||
} | ||
} | ||
|
||
/* Our response to the "SUBMIT" is to simply send the same page again*/ | ||
return "/cgi.html"; | ||
} | ||
|
||
/* cgi-handler triggered by a request for "/leds_ext.cgi". | ||
* | ||
* It is almost identical to cgi_handler_basic(). | ||
* Both handlers could be easily implemented in one function - | ||
* distinguish them by looking at the iIndex parameter. | ||
* I left it this way to show how to implement two (or more) | ||
* enirely different handlers. | ||
*/ | ||
const char * | ||
cgi_handler_extended(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) | ||
{ | ||
int i=0; | ||
|
||
/* We use this handler for one page request only: "/leds_ext.cgi" | ||
* and it is at position 1 in the tCGI array (see above). | ||
* So iIndex should be 1. | ||
*/ | ||
printf("cgi_handler_extended called with index %d\n", iIndex); | ||
|
||
/* All leds off */ | ||
Led_Off(LED1); | ||
Led_Off(LED2); | ||
Led_Off(LED3); | ||
Led_Off(LED4); | ||
|
||
/* Check the query string. | ||
* A request to turn LED2 and LED4 on would look like: "/leds.cgi?led=2&led=4" | ||
*/ | ||
for (i = 0; i < iNumParams; i++){ | ||
/* check if parameter is "led" */ | ||
if (strcmp(pcParam[i] , "led") == 0){ | ||
/* look ar argument to find which led to turn on */ | ||
if(strcmp(pcValue[i], "1") == 0) | ||
Led_On(LED1); | ||
else if(strcmp(pcValue[i], "2") == 0) | ||
Led_On(LED2); | ||
else if(strcmp(pcValue[i], "3") == 0) | ||
Led_On(LED3); | ||
else if(strcmp(pcValue[i], "4") == 0) | ||
Led_On(LED4); | ||
} | ||
} | ||
|
||
/* Our response to the "SUBMIT" is to send "/ssi_cgi.shtml". | ||
* The extension ".shtml" tells the server to insert some values | ||
* which show the user what has been done in response. | ||
*/ | ||
return "/ssi_cgi.shtml"; | ||
} | ||
|
||
/* initialize the CGI handler */ | ||
void | ||
cgi_init(void) | ||
{ | ||
http_set_cgi_handlers(cgi_handlers, 2); | ||
|
||
for(int i = LED1; i <= LED4; i++){ | ||
gpio_init(i); | ||
gpio_set_dir(i, GPIO_OUT); | ||
gpio_put(i, 0); | ||
} | ||
} | ||
|
||
/* led control and debugging info */ | ||
void | ||
Led_On(int led) | ||
{ | ||
printf("GPIO%d on\n", led); | ||
gpio_put(led, 1); | ||
} | ||
|
||
void | ||
Led_Off(int led) | ||
{ | ||
printf("GPIO%d off\n", led); | ||
gpio_put(led, 0); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef __CGI_H__ | ||
#define __CGI_H__ | ||
|
||
// GPIOs for Leds | ||
#define LED1 18 | ||
#define LED2 19 | ||
#define LED3 20 | ||
#define LED4 21 | ||
|
||
/* initialize the CGI handler */ | ||
void cgi_init(void); | ||
|
||
/* CGI handler for LED control */ | ||
const char * cgi_handler_basic(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]); | ||
/* CGI handler for LED control with feedback*/ | ||
const char * cgi_handler_extended(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]); | ||
|
||
|
||
/* led control and debugging info */ | ||
void Led_On(int led); | ||
void Led_Off(int led); | ||
|
||
#endif // __CGI_H__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> <title>Pico W CGI-PAGE</title> </head> | ||
<body> <h1>Pico W</h1> | ||
<h3>CGI-PAGE</h3> | ||
|
||
<span> | ||
This page allows you to control four leds: LED1, LED2, LED3 and LED4 connected to GPIO18 - 21<br><br> | ||
To turn a led on/off check/uncheck its corresponding checkbox.<br> | ||
Then click on the "Send" button to submit the changes.<br> | ||
</span> | ||
<br> | ||
<form method="get" action="/leds.cgi"> | ||
<input value="1" name="led" type="checkbox">LED1<br> | ||
<input value="2" name="led" type="checkbox">LED2<br> | ||
<input value="3" name="led" type="checkbox">LED3<br> | ||
<input value="4" name="led" type="checkbox">LED4<br> | ||
<br> | ||
<input value="Send" type="submit"> | ||
</form> | ||
<br> | ||
<br> | ||
<a href="/index.html">Back</a> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> <title>Pico W</title> </head> | ||
<body> <h1>Pico W</h1> | ||
<head> <title>Pico W SSI-PAGE</title> </head> | ||
<body> | ||
<h1>Pico W</h1> | ||
<h3>SSI-PAGE</h3> | ||
<p><!--#Hello--> Times <!--#counter-->!</p> | ||
<p>GPIO26 voltage is: <!--#GPIO-->!</p> | ||
<br> | ||
<br> | ||
<a href="/index.html">Back</a> | ||
</body> | ||
</html> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> <title>Pico W CGI-SSI-PAGE</title> </head> | ||
<body> <h1>Pico W</h1> | ||
<h3>CGI with Feedback (ssi) PAGE</h3> | ||
|
||
<span> | ||
This page allows you to control four leds: LED1, LED2, LED3 and LED4 connected to GPIO18 - 21<br><br> | ||
To turn a led on/off check/uncheck its corresponding checkbox.<br> | ||
Then click on the "Send" button to submit the changes.<br> | ||
</span> | ||
<br> | ||
<form method="get" action="/leds_ext.cgi"> | ||
<input value="1" name="led" type="checkbox" <!--#state1-->> | ||
<span style=<!--#bg1-->>LED1</span><br> | ||
<input value="2" name="led" type="checkbox" <!--#state2-->> | ||
<span style=<!--#bg2-->>LED2</span><br> | ||
<input value="3" name="led" type="checkbox" <!--#state3-->> | ||
<span style=<!--#bg3-->>LED3</span><br> | ||
<input value="4" name="led" type="checkbox" <!--#state4-->> | ||
<span style=<!--#bg4-->>LED4</span><br> | ||
<input value="Send" type="submit"> | ||
</form> | ||
<br> | ||
<br> | ||
<a href="/index.html">Back</a> | ||
</body> | ||
</html> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that was added by mistake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I didn't realize that Kate was an editor 😅