Skip to content

Commit

Permalink
Merge pull request #30 from PropGit/master
Browse files Browse the repository at this point in the history
Added BadgeWX Support.
  • Loading branch information
PropGit authored Jul 20, 2018
2 parents 5e32b8c + 1dfedb5 commit 5c340ae
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
build/
nbproject/
release/release
release/patch
*.zip
*.bin
*.elf
*.ld
*.bak
*~
test-framework-*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ VERSION=$(GIT_VERSION) ($(shell date "+%Y-%m-%d %H:%M:%S")$(GIT_COMMIT_HASH_SUFF
$(info VERSION $(VERSION))

#SPI flash size, in K
ESP_SPI_FLASH_SIZE_K=4096
ESP_SPI_FLASH_SIZE_K=2048
#Amount of the flash to use for the image(s)
ESP_SPI_IMAGE_SIZE_K=1024
#0: QIO, 1: QOUT, 2: DIO, 3: DOUT
Expand Down
27 changes: 20 additions & 7 deletions parallax/cgiprop.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int ICACHE_FLASH_ATTR cgiPropInit()
os_timer_setfn(&resetButtonTimer, resetButtonTimerCallback, 0);
os_timer_arm(&resetButtonTimer, RESET_BUTTON_SAMPLE_INTERVAL, 1);

#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
makeGpio(AUTO_LOAD_PIN);
PIN_PULLUP_EN(PERIPHS_IO_MUX_MTMS_U);
GPIO_DIS_OUTPUT(AUTO_LOAD_PIN);
Expand Down Expand Up @@ -125,7 +125,7 @@ int ICACHE_FLASH_ATTR cgiPropInit()
}
}

#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (IsAutoLoadEnabled()) {
int sts;
os_printf("Autoloading 'autorun.bin'\n");
Expand Down Expand Up @@ -154,7 +154,7 @@ int ICACHE_FLASH_ATTR cgiPropLoad(HttpdConnData *connData)
return HTTPD_CGI_DONE;
}

#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand Down Expand Up @@ -217,7 +217,7 @@ int ICACHE_FLASH_ATTR cgiPropLoadFile(HttpdConnData *connData)
return HTTPD_CGI_DONE;
}

#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand Down Expand Up @@ -268,7 +268,7 @@ int ICACHE_FLASH_ATTR cgiPropReset(HttpdConnData *connData)
return HTTPD_CGI_DONE;
}

#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand Down Expand Up @@ -603,10 +603,23 @@ static void ICACHE_FLASH_ATTR readCallback(char *buf, short length)
#endif
}

#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
int ICACHE_FLASH_ATTR IsAutoLoadEnabled(void)
{
return GPIO_INPUT_GET(AUTO_LOAD_PIN) == AUTO_LOAD_PIN_STATE;
int autoLoadButtonState = GPIO_INPUT_GET(AUTO_LOAD_PIN);
static int lastAutoLoadButtonState = 0;

static uint32_t lastAutoLoadTime = 0;
uint32_t autoLoadTime = system_get_time() / 1000;

if (lastAutoLoadButtonState == 1 && autoLoadTime - lastAutoLoadTime < 5000) {
autoLoadButtonState = 1; // Override if less than 10 seconds ellapsed since last call
}

lastAutoLoadButtonState = autoLoadButtonState;
lastAutoLoadTime = autoLoadTime;

return ((autoLoadButtonState == AUTO_LOAD_PIN_STATE) && (GPIO_INPUT_GET(RESET_BUTTON_PIN) != 0));
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions parallax/httpdroffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ cgiRoffsHook(HttpdConnData *connData) {

int ICACHE_FLASH_ATTR cgiRoffsFormat(HttpdConnData *connData)
{
#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand All @@ -133,7 +133,7 @@ int ICACHE_FLASH_ATTR cgiRoffsWriteFile(HttpdConnData *connData)
{
ROFFS_FILE *file = connData->cgiData;

#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand Down
41 changes: 39 additions & 2 deletions parallax/sscp-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@ void ICACHE_FLASH_ATTR cmds_do_nothing(int argc, char *argv[])
// JOIN,ssid,passwd
void ICACHE_FLASH_ATTR cmds_do_join(int argc, char *argv[])
{
if (argc != 3) {
if (argc == 1) {

// Auto Join!
wifiJoinAuto();
sscp_sendResponse("S,0");
return;
}

else if (argc != 3) {
sscp_sendResponse("E,%d", SSCP_ERROR_WRONG_ARGUMENT_COUNT);
return;
}

if (wifiJoin(argv[1], argv[2]) == 0)
sscp_sendResponse("S,0");
else
sscp_sendResponse("E,%d", SSCP_ERROR_INVALID_ARGUMENT);
sscp_sendResponse("E,%d", SSCP_ERROR_INVALID_ARGUMENT); // mm: This can never be called ???!! wifiJoin can only return 0 as currently coded
}

static void ICACHE_FLASH_ATTR path_handler(sscp_hdr *hdr)
Expand Down Expand Up @@ -161,6 +169,35 @@ void ICACHE_FLASH_ATTR cmds_do_close(int argc, char *argv[])
sscp_sendResponse("S,0");
}

// RESTART,hard
void ICACHE_FLASH_ATTR cmds_do_restart(int argc, char *argv[])
{
if (argc != 2) {
sscp_sendResponse("E,%d", SSCP_ERROR_WRONG_ARGUMENT_COUNT);
return;
}

if (atoi(argv[1]) == 0) {
sscp_log("RESTART 0 : system_restart");
//ESP.restart();
system_restart();
sscp_sendResponse("S,0");
return;

} else if (atoi(argv[1]) == 1) {
sscp_log("RESTART 1 : system_upgrade_reboot");
//ESP.reset();
system_upgrade_reboot();
sscp_sendResponse("S,0");
return;

} else {

sscp_sendResponse("E,%d", SSCP_ERROR_INVALID_ARGUMENT);
return;
}
}

// SEND,chan,count
void ICACHE_FLASH_ATTR cmds_do_send(int argc, char *argv[])
{
Expand Down
8 changes: 4 additions & 4 deletions parallax/sscp-settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ int ICACHE_FLASH_ATTR cgiPropSetting(HttpdConnData *connData)
cmd_def *def = NULL;
int i;

#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (connData->requestType == HTTPD_METHOD_POST && IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand Down Expand Up @@ -514,7 +514,7 @@ int ICACHE_FLASH_ATTR cgiPropSetting(HttpdConnData *connData)

int ICACHE_FLASH_ATTR cgiPropSaveSettings(HttpdConnData *connData)
{
#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand All @@ -528,7 +528,7 @@ int ICACHE_FLASH_ATTR cgiPropSaveSettings(HttpdConnData *connData)

int ICACHE_FLASH_ATTR cgiPropRestoreSettings(HttpdConnData *connData)
{
#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand All @@ -542,7 +542,7 @@ int ICACHE_FLASH_ATTR cgiPropRestoreSettings(HttpdConnData *connData)

int ICACHE_FLASH_ATTR cgiPropRestoreDefaultSettings(HttpdConnData *connData)
{
#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand Down
35 changes: 31 additions & 4 deletions parallax/sscp-wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ void ICACHE_FLASH_ATTR wifi_do_apscan(int argc, char *argv[])
return;
}

cgiWiFiStartScan(scan_complete, NULL);

sscp_sendResponse("S,0");
scanDone = 0;

if (cgiWiFiStartScan(scan_complete, NULL) == 1) {
sscp_sendResponse("S,0");
} else {
sscp_sendResponse("E,%d", SSCP_ERROR_BUSY);
}
}

// APGET:index
Expand All @@ -68,10 +72,33 @@ void ICACHE_FLASH_ATTR wifi_do_apget(int argc, char *argv[])
else {
ApData *entry = cgiWiFiScanResult(index);
if (entry)
sscp_sendResponse("S,%d,%s,%d", entry->enc, entry->ssid, entry->rssi);
//sscp_sendResponse("S,%d,%s,%d", entry->enc, entry->ssid, entry->rssi); //Originally released with variable-length string as second-to-last field; inconsistent with rest of API
sscp_sendResponse("S,%d,%d,%s", entry->enc, entry->rssi, entry->ssid);
else
sscp_sendResponse("E,%d", SSCP_ERROR_INVALID_ARGUMENT);
}
}



// APSET,ssid,passwd, optional flag for restart
void ICACHE_FLASH_ATTR wifi_do_apset(int argc, char *argv[])
{
if (argc == 4) { // Special case- restart after command
sscp_sendResponse("S,0");
wifiSetCredentials(argv[1], argv[2], 1);

This comment has been minimized.

Copy link
@ClockLoop

ClockLoop Nov 10, 2018

Cannot compile?

parallax/sscp-wifi.c: In function 'wifi_do_apset':
parallax/sscp-wifi.c:89:9: error: implicit declaration of function 'wifiSetCredentials' [-Werror=implicit-function-declaration]
         wifiSetCredentials(argv[1], argv[2], 1);
         ^
cc1: all warnings being treated as errors
Makefile:252: recipe for target 'build/parallax/sscp-wifi.o' failed
make: *** [build/parallax/sscp-wifi.o] Error 1
return;
}
else if (argc != 3) {
sscp_sendResponse("E,%d", SSCP_ERROR_WRONG_ARGUMENT_COUNT);
return;
}

if (wifiSetCredentials(argv[1], argv[2], 0) == 0)

This comment has been minimized.

Copy link
@ClockLoop

ClockLoop Nov 10, 2018

I cannot compile many changes made on this same date... multiple implicit declaration errors.

CC parallax/sscp-wifi.c
parallax/sscp-wifi.c: In function 'wifi_do_apset':
parallax/sscp-wifi.c:97:5: error: implicit declaration of function 'wifiSetCredentials' [-Werror=implicit-function-declaration]
     if (wifiSetCredentials(argv[1], argv[2], 0) == 0)
     ^
cc1: all warnings being treated as errors
Makefile:252: recipe for target 'build/parallax/sscp-wifi.o' failed
make: *** [build/parallax/sscp-wifi.o] Error 1
sscp_sendResponse("S,0");
else
sscp_sendResponse("E,%d", SSCP_ERROR_INVALID_ARGUMENT);
}



6 changes: 6 additions & 0 deletions parallax/sscp.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,13 @@ static cmd_def cmds[] = {
{ "SEND", cmds_do_send },
{ "RECV", cmds_do_recv },
{ "CLOSE", cmds_do_close },
{ "RESTART", cmds_do_restart },
{ "ARG", http_do_arg },
{ "REPLY", http_do_reply },
{ "CONNECT", tcp_do_connect },
{ "APSCAN", wifi_do_apscan },
{ "APGET", wifi_do_apget },
{ "APSET", wifi_do_apset },
{ "FINFO", fs_do_finfo },
{ "FCOUNT", fs_do_fcount },
{ "FRUN", fs_do_frun },
Expand Down Expand Up @@ -472,12 +474,14 @@ void ICACHE_FLASH_ATTR sscp_filter(char *buf, short len, void (*outOfBand)(void
case SSCP_TKN_SEND:
case SSCP_TKN_RECV:
case SSCP_TKN_CLOSE:
case SSCP_TKN_RESTART:
case SSCP_TKN_LISTEN:
case SSCP_TKN_ARG:
case SSCP_TKN_REPLY:
case SSCP_TKN_CONNECT:
case SSCP_TKN_APSCAN:
case SSCP_TKN_APGET:
case SSCP_TKN_APSET:
case SSCP_TKN_HTTP:
case SSCP_TKN_WS:
case SSCP_TKN_TCP:
Expand All @@ -496,12 +500,14 @@ void ICACHE_FLASH_ATTR sscp_filter(char *buf, short len, void (*outOfBand)(void
case SSCP_TKN_SEND: name = "SEND"; sep = ':'; break;
case SSCP_TKN_RECV: name = "RECV"; sep = ':'; break;
case SSCP_TKN_CLOSE: name = "CLOSE"; sep = ':'; break;
case SSCP_TKN_RESTART: name = "RESTART"; sep = ':'; break;
case SSCP_TKN_LISTEN: name = "LISTEN"; sep = ':'; break;
case SSCP_TKN_ARG: name = "ARG"; sep = ':'; break;
case SSCP_TKN_REPLY: name = "REPLY"; sep = ':'; break;
case SSCP_TKN_CONNECT: name = "CONNECT"; sep = ':'; break;
case SSCP_TKN_APSCAN: name = "APSCAN"; sep = ':'; break;
case SSCP_TKN_APGET: name = "APGET"; sep = ':'; break;
case SSCP_TKN_APSET: name = "APSET"; sep = ':'; break;
case SSCP_TKN_FINFO: name = "FINFO"; sep = ':'; break;
case SSCP_TKN_FCOUNT: name = "FCOUNT"; sep = ':'; break;
case SSCP_TKN_FRUN: name = "FRUN"; sep = ':'; break;
Expand Down
6 changes: 4 additions & 2 deletions parallax/sscp.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ enum {
SSCP_TKN_STA = 0xF4,
SSCP_TKN_AP = 0xF3,
SSCP_TKN_STA_AP = 0xF2,

// gap for more tokens
SSCP_TKN_APSET = 0xF1,
SSCP_TKN_RESTART = 0xF0,

SSCP_TKN_JOIN = 0xEF,
SSCP_TKN_CHECK = 0xEE,
Expand Down Expand Up @@ -189,6 +189,7 @@ void cmds_do_path(int argc, char *argv[]);
void cmds_do_send(int argc, char *argv[]);
void cmds_do_recv(int argc, char *argv[]);
void cmds_do_close(int argc, char *argv[]);
void cmds_do_restart(int argc, char *argv[]);
int cgiPropEnableSerialProtocol(HttpdConnData *connData);
int cgiPropModuleInfo(HttpdConnData *connData);

Expand Down Expand Up @@ -217,6 +218,7 @@ void tcp_do_connect(int argc, char *argv[]);
// from sscp-wifi.c
void wifi_do_apscan(int argc, char *argv[]);
void wifi_do_apget(int argc, char *argv[]);
void wifi_do_apset(int argc, char *argv[]);
int wifi_check_for_events(void);

// from sscp-fs.c
Expand Down
11 changes: 7 additions & 4 deletions parallax/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ CgiUploadFlashDef uploadParams={
#endif

static int ICACHE_FLASH_ATTR cgiGetFirmwareNextFilter(HttpdConnData *connData) {
#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (connData->conn != NULL && IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand All @@ -141,7 +141,7 @@ static int ICACHE_FLASH_ATTR cgiGetFirmwareNextFilter(HttpdConnData *connData) {
}

int ICACHE_FLASH_ATTR cgiUploadFirmwareFilter(HttpdConnData *connData) {
#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (connData->conn != NULL && IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand All @@ -151,7 +151,7 @@ int ICACHE_FLASH_ATTR cgiUploadFirmwareFilter(HttpdConnData *connData) {
}

int ICACHE_FLASH_ATTR cgiWiFiConnectFilter(HttpdConnData *connData) {
#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (connData->conn != NULL && IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand All @@ -161,7 +161,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnectFilter(HttpdConnData *connData) {
}

int ICACHE_FLASH_ATTR cgiWiFiSetModeFilter(HttpdConnData *connData) {
#ifdef WIFI_BADGE
#ifdef AUTO_LOAD
if (connData->conn != NULL && IsAutoLoadEnabled()) {
httpdSendResponse(connData, 400, "Not allowed\r\n", -1);
return HTTPD_CGI_DONE;
Expand Down Expand Up @@ -240,8 +240,11 @@ static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg) {
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
void ICACHE_FLASH_ATTR user_init(void) {
int restoreOk;

//wifi_station_set_auto_connect(TRUE); // Default on; may be overwritten by valid flash config

if (!(restoreOk = configRestore()))
//wifi_station_set_auto_connect(TRUE); // Default on; may be overwritten by valid flash config
configSave();

wifi_station_set_hostname(flashConfig.module_name);
Expand Down

0 comments on commit 5c340ae

Please sign in to comment.