Skip to content
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

Variable TCP Telnet ports via web interface #205

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
563957f
Update home.html
fuzzball03 Oct 27, 2016
143eb24
Update ui.js
fuzzball03 Oct 27, 2016
eb7fde7
Update cgipins.c
fuzzball03 Oct 27, 2016
5cb0350
Update config.h
fuzzball03 Oct 27, 2016
fb1bbd3
Update config.h
fuzzball03 Oct 27, 2016
93ca100
Update config.c
fuzzball03 Oct 27, 2016
02197a9
Create cgitelnet.h
fuzzball03 Oct 27, 2016
8919ff6
Update cgitelnet.h
fuzzball03 Oct 27, 2016
f315385
Create cgitelnet.c
fuzzball03 Oct 27, 2016
59edf88
Update serbridge.c
fuzzball03 Oct 27, 2016
6054496
Update serbridge.c
fuzzball03 Oct 27, 2016
a230f42
Update main.c
fuzzball03 Oct 27, 2016
4bddea7
Update main.c
fuzzball03 Oct 27, 2016
04bbccb
Update main.c
fuzzball03 Oct 27, 2016
936951d
Update main.c
fuzzball03 Oct 27, 2016
0009d8f
Update cgitelnet.c
fuzzball03 Oct 27, 2016
bead65f
Update cgitelnet.c
fuzzball03 Oct 27, 2016
c3a3b06
Update serbridge.c
fuzzball03 Oct 27, 2016
67a05de
Update cgitelnet.c
fuzzball03 Oct 27, 2016
1cf190a
Update cgitelnet.c
fuzzball03 Oct 27, 2016
6fb97bd
Update config.h
fuzzball03 Oct 27, 2016
a01db32
Update cgitelnet.c
fuzzball03 Oct 27, 2016
157569e
Cgitelnet changes/fixes
fuzzball03 Oct 28, 2016
fe95b4b
Cleanup
fuzzball03 Oct 28, 2016
ffd13c6
Ajax/Html changes
fuzzball03 Oct 28, 2016
3cb3804
Cgitelnet update
fuzzball03 Oct 28, 2016
a9f583e
Update cgitelnet.c
fuzzball03 Oct 28, 2016
7a93821
Update cgitelnet.c
fuzzball03 Oct 28, 2016
00d8b9f
Update cgitelnet.c
fuzzball03 Oct 28, 2016
973e4fb
Update .travis.yml
fuzzball03 Oct 28, 2016
b79a6d6
update for s3
fuzzball03 Oct 28, 2016
d887feb
Update .travis.yml
fuzzball03 Oct 28, 2016
e25d896
Update .travis.yml
fuzzball03 Oct 28, 2016
30658c5
Update .travis.yml
fuzzball03 Oct 28, 2016
8cd915f
Cgitelnet reform json output
fuzzball03 Oct 28, 2016
1da3ce7
Update cgitelnet.c
fuzzball03 Oct 28, 2016
6a730e7
Update cgitelnet.c
fuzzball03 Oct 28, 2016
7d60520
Update home.html
fuzzball03 Oct 28, 2016
338f983
Update readme to reflect changes
fuzzball03 Oct 31, 2016
3fdfe93
Various changes
fuzzball03 Oct 31, 2016
3f16121
Fix a few errors..
fuzzball03 Oct 31, 2016
2458e11
Serialbridge.c update
fuzzball03 Oct 31, 2016
27e6b5d
Fix compile errors
dannybackx Nov 1, 2016
36f15c9
Fix compile errors
dannybackx Nov 1, 2016
59a4707
Fix compile errors
dannybackx Nov 1, 2016
654f2ef
Fix compile errors
dannybackx Nov 1, 2016
4b3293e
Change comment
dannybackx Nov 1, 2016
547540d
Fix the build problem : don't call sprintf.
dannybackx Nov 1, 2016
589158e
Aha
dannybackx Nov 1, 2016
f3060e6
Change call to 0/1 instead of 1/2
dannybackx Nov 1, 2016
286e886
Makefile/Build file changes
fuzzball03 Nov 3, 2016
6596883
Formatting cleanup
fuzzball03 Nov 3, 2016
0b8368a
Modify all calls to port variables to match. Espconn1 = TelnetPort1
fuzzball03 Nov 3, 2016
b8404a1
Fix error for sucessful Travis build
fuzzball03 Nov 3, 2016
bda82de
Start making changes for Danny's security settings
fuzzball03 Nov 4, 2016
623f7b4
fix error
fuzzball03 Nov 4, 2016
5e346a3
Fix errors
fuzzball03 Nov 4, 2016
b5243b0
HTML Changes.
fuzzball03 Nov 4, 2016
6fd5938
Update .travis.yml
fuzzball03 Nov 16, 2016
25feca5
Update .travis.yml
fuzzball03 Nov 23, 2016
23a904f
5
fuzzball03 Nov 23, 2016
1df972b
9
fuzzball03 Nov 23, 2016
153f470
10
fuzzball03 Nov 23, 2016
9fcee90
12
fuzzball03 Nov 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
# Travis-CI file for Esp-Link

language: c

before_install:
- curl -Ls http://s3.voneicken.com/xtensa-lx106-elf-20160330.tgx | tar Jxf -
- curl -Ls http://s3.voneicken.com/esp_iot_sdk_v2.0.0.p1.tgx | tar -C .. -Jxf -

- curl -Ls http://s3.voneicken.com/xtensa-lx106-elf-20160330.tgx | tar Jxf -
- curl -Ls http://s3.voneicken.com/esp_iot_sdk_v2.0.0.p1.tgx | tar -C .. -Jxf -
after_script:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why all these formatting changes here? please don't make random formatting changes, it makes reviewing difficult, plus, I don't see why your formatting is better than mine...

# upload to an S3 bucket, requires S3_BUCKET, AWS_ACCESS_KEY_ID and AWS_SECRET_KEY to be set
# in environment using travis' repository settings
- "if [[ -n \"$S3_BUCKET\" && -n \"$AWS_ACCESS_KEY_ID\" ]]; then
echo Uploading *.tgz to $S3_BUCKET;
curl -Ls https://github.com/rlmcpherson/s3gof3r/releases/download/v0.5.0/gof3r_0.5.0_linux_amd64.tar.gz | tar zxf - gof3r_0.5.0_linux_amd64/gof3r;
mv gof3r*/gof3r .;
ls *.tgz | xargs -I {} ./gof3r put -b $S3_BUCKET -k esp-link/{} --acl public-read -p {};
ls *.tgz | xargs -I {} echo \"URL: http://$S3_BUCKET/esp-link/{}\";
fi"

- 'if [[ -n "$S3_BUCKET" && -n "$AWS_ACCESS_KEY_ID" ]]; then echo Uploading *.tgz
to $S3_BUCKET; curl -Ls https://github.com/rlmcpherson/s3gof3r/releases/download/v0.5.0/gof3r_0.5.0_linux_amd64.tar.gz
| tar zxf - gof3r_0.5.0_linux_amd64/gof3r; mv gof3r*/gof3r .; ls *.tgz | xargs -I
{} ./gof3r put -b $S3_BUCKET -k esp-link/{} --acl public-read -p {}; ls *.tgz |
xargs -I {} echo "URL: http://$S3_BUCKET/esp-link/{}"; fi'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this change about?

compiler: gcc

env:

env:
script:
- export XTENSA_TOOLS_ROOT=$PWD/xtensa-lx106-elf/bin/
- export BRANCH=$TRAVIS_BRANCH
#- export SDK_BASE=$PWD/esp_iot_sdk_v2.0.0.p1
- make release

- export XTENSA_TOOLS_ROOT=$PWD/xtensa-lx106-elf/bin/
- export BRANCH=$TRAVIS_BRANCH
- make release
notifications:
email: false
deploy:
skip_cleanup: true
provider: releases
api_key:
secure: unYyTCLpk1ixcNOyoUwroBqqx0yBhii56IXm57kjo5kl3umf1GRb3FUIE6la+B0njsNwAUNR/uLn6wF4FqYTUJzNQZskJDJfZjb53vwuoHaoa5j4K/bWB9zRlQ1XZBTkV48cxz8Ef2KyNduK2IciOHwsw3LQS0em3dpK7oG/20VzELt23Gx8uhBYa+OUzlr3Y+PYPynkwM30YwVQXpCy/GMgEbrcKheGbLTAIp7tms0KDAvbb98U0BI3tWBckE5GzAYYAmrXgyDXtEsU/poCMqUj/lpPl1s/5uxGVevTO7XuL4AYtF//AixsM20bPKtIZDHZS9b7JHtVhU655bY2aAfpMgf7xzkKbJkRzeAzT9HucFDjLY48yW4vztdJxBgkAL9d064gTHhThtn4hylZAYpHnqUiM0j4DKil5A0VG2F8EVEqZ7Q2tNzy6aqq37wzTuYXsYpz3mglpazaXXp/LoSurDHy1gz6aB/mdaeBoL3MX1q09LBE8lFGYBILQ8KUkrLyJathxAVvDBnl7nXFv2NWoZ2i7CfXdpCwmOVUN2WhudNfgbbaMung+voTFB+yLq9PBQP5gdP0MKU3zDTB/msmZo1pp/SbnNETCrKAdRtxNI+bxTQ98njAIkxI+7ZiVV8SMNEPyNcWq/6ViYDcIHJMR4Gq0DZunre1voEs1F4=
file_glob: true
file: esp-link-master-*.t*gz
on:
repo: fuzzball03/esp-link
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this change about?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore any Travis changes please.
I've done those changes so any commits made on my fork will compile via Travis without the need for me to build it myself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mhh, I'm not a fan of having to go and clean-up after you ;-) but I also see that the uploads aren't working for pull requests. I had thought that they would. I think the solution is for me to provide my S3 keys to anyone who wants to have the builds done automatically.

64 changes: 39 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ ESP_HOSTNAME ?= esp-link
# Base directory for the compiler. Needs a / at the end.
# Typically you'll install https://github.com/pfalcon/esp-open-sdk
# IMPORTANT: use esp-open-sdk `make STANDALONE=n`: the SDK bundled with esp-open-sdk will *not* work!
XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
XTENSA_TOOLS_ROOT ?= $(abspath ../espressif/xtensa-lx106-elf/bin)/
$(warning Using XTENSA TOOLS from $(XTENSA_TOOLS_ROOT))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look at this commit for a more thorough explanation of changes made in Makefile
fuzzball03@286e886

# Firmware version
# WARNING: if you change this expect to make code adjustments elsewhere, don't expect
# that esp-link will magically work with a different version of the SDK!!!
SDK_VERS ?= esp_iot_sdk_v2.0.0.p1
# Uncomment this line if you're using windows to build with the C:\espressif structure
# SDK_VERS ?= ESP8266_SDK

# Try to find the firmware manually extracted, e.g. after downloading from Espressif's BBS,
# http://bbs.espressif.com/viewforum.php?f=46
Expand All @@ -66,16 +69,17 @@ SDK_BASE ?= $(wildcard ../$(SDK_VERS))

# If the firmware isn't there, see whether it got downloaded as part of esp-open-sdk
# This used to work at some point, but is not supported, uncomment if you feel lucky ;-)
#ifeq ($(SDK_BASE),)
#SDK_BASE := $(wildcard $(XTENSA_TOOLS_ROOT)/../../$(SDK_VERS))
#endif
ifeq ($(SDK_BASE),)
SDK_BASE := $(wildcard $(XTENSA_TOOLS_ROOT)/../../$(SDK_VERS))
endif

# Clean up SDK path
SDK_BASE := $(abspath $(SDK_BASE))
$(warning Using SDK from $(SDK_BASE))

# Path to bootloader file
BOOTFILE ?= $(SDK_BASE/bin/boot_v1.6.bin)
BOOTFILE ?= $(SDK_BASE)/bin/boot_v1.6.bin
$(warning Using boot file-> $(BOOTFILE))

# Esptool.py path and port, only used for 1-time serial flashing
# Typically you'll use https://github.com/themadinventor/esptool
Expand Down Expand Up @@ -127,8 +131,10 @@ GZIP_COMPRESSION ?= yes
# http://yui.github.io/yuicompressor/
# enabled by default.
COMPRESS_W_HTMLCOMPRESSOR ?= yes
HTML_COMPRESSOR ?= htmlcompressor-1.5.3.jar
YUI_COMPRESSOR ?= yuicompressor-2.4.8.jar
HTML_COMPRESSOR_VER ?= htmlcompressor-1.5.3.jar
HTML_COMPRESSOR = tools/$(HTML_COMPRESSOR_VER)
YUI_COMPRESSOR_VER ?= yuicompressor-2.4.8.jar
YUI_COMPRESSOR = tools/$(YUI_COMPRESSOR_VER)

# -------------- End of config options -------------

Expand Down Expand Up @@ -296,6 +302,13 @@ Q := @
vecho := @echo
endif

#Fix for issues on some windows systems that call non GNU FIND
FIND ?= $(which FIND)
ifeq (,$(findstring system32,$(FIND)))
$(warning Non GNU 'find' called. Trying alternate path /usr/bin/find)
FIND = /usr/bin/find
endif

ifneq ($(strip $(STA_SSID)),)
CFLAGS += -DSTA_SSID="$(STA_SSID)"
endif
Expand Down Expand Up @@ -387,6 +400,7 @@ $(FW_BASE)/user2.bin: $(USER2_OUT) $(FW_BASE)
$(Q) COMPILE=gcc PATH=$(XTENSA_TOOLS_ROOT):$(PATH) python $(APPGEN_TOOL) $(USER2_OUT) 2 $(ESP_FLASH_MODE) $(ESP_FLASH_FREQ_DIV) $(ESP_SPI_SIZE) 1 >/dev/null
$(Q) rm -f eagle.app.v6.*.bin
$(Q) mv eagle.app.flash.bin $@
@echo "** user2.bin uses $$(stat -c '%s' $@) bytes of" $(ESP_FLASH_MAX) "available"
$(Q) if [ $$(stat -c '%s' $@) -gt $$(( $(ESP_FLASH_MAX) )) ]; then echo "$@ too big!"; false; fi

$(APP_AR): $(OBJ)
Expand All @@ -406,18 +420,18 @@ baseflash: all

flash: all
$(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \
0x00000 "$(SDK_BASE)/bin/boot_v1.5.bin" 0x01000 $(FW_BASE)/user1.bin \
0x00000 "$(BOOTFILE)" 0x01000 $(FW_BASE)/user1.bin \
$(ET_BLANK) $(SDK_BASE)/bin/blank.bin

tools/$(HTML_COMPRESSOR):
$(Q) echo "The jar files in the tools dir are missing, they should be in the source repo"
$(Q) echo "The following commands can be used to fetch them, but the URLs have changed..."
$(Q) echo mkdir -p tools
$(Q) echo "cd tools; wget --no-check-certificate https://github.com/yui/yuicompressor/releases/download/v2.4.8/$(YUI_COMPRESSOR) -O $(YUI_COMPRESSOR)"
$(Q) echo "cd tools; wget --no-check-certificate https://htmlcompressor.googlecode.com/files/$(HTML_COMPRESSOR) -O $(HTML_COMPRESSOR)"
$(Q) echo "cd tools; wget --no-check-certificate https://github.com/yui/yuicompressor/releases/download/v2.4.8/$(YUI_COMPRESSOR_VER) -O $(YUI_COMPRESSOR_VER)"
$(Q) echo "cd tools; wget --no-check-certificate https://htmlcompressor.googlecode.com/files/$(HTML_COMPRESSOR_VER) -O $(HTML_COMPRESSOR_VER)"

ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes")
$(BUILD_BASE)/espfs_img.o: tools/$(HTML_COMPRESSOR)
$(BUILD_BASE)/espfs_img.o: $(HTML_COMPRESSOR)
endif

$(BUILD_BASE)/espfs_img.o: html/ html/wifi/ espfs/mkespfsimage/mkespfsimage
Expand All @@ -428,38 +442,38 @@ $(BUILD_BASE)/espfs_img.o: html/ html/wifi/ espfs/mkespfsimage/mkespfsimage
$(Q) cp -r html/wifi/*.png html_compressed/wifi;
$(Q) cp -r html/wifi/*.js html_compressed/wifi;
ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes")
$(Q) echo "Compressing assets with htmlcompressor. This may take a while..."
$(Q) java -jar tools/$(HTML_COMPRESSOR) \
$(Q) echo "Compressing assets with htmlcompressor. This may take a while...";
$(Q) java -jar $(HTML_COMPRESSOR) \
-t html --remove-surrounding-spaces max --remove-quotes --remove-intertag-spaces \
-o $(abspath ./html_compressed)/ \
$(HTML_PATH)head- \
$(HTML_PATH)*.html
$(Q) java -jar tools/$(HTML_COMPRESSOR) \
$(Q) java -jar $(HTML_COMPRESSOR) \
-t html --remove-surrounding-spaces max --remove-quotes --remove-intertag-spaces \
-o $(abspath ./html_compressed)/wifi/ \
$(WIFI_PATH)*.html
$(Q) echo "Compressing assets with yui-compressor. This may take a while..."
$(Q) for file in `find html_compressed -type f -name "*.js"`; do \
java -jar tools/$(YUI_COMPRESSOR) $$file --line-break 0 -o $$file; \
done
$(Q) for file in `find html_compressed -type f -name "*.css"`; do \
java -jar tools/$(YUI_COMPRESSOR) $$file -o $$file; \
done
$(Q) java -jar $(YUI_COMPRESSOR) ./html_compressed/*.css -o '.css$:.css'
$(Q) java -jar $(YUI_COMPRESSOR) ./html_compressed/*.js -o '.js$:.js'
$(Q) java -jar $(YUI_COMPRESSOR) ./html_compressed/wifi/*.js -o '.js$:.js'
else
$(Q) cp -r html/head- html_compressed;
$(Q) cp -r html/*.html html_compressed;
$(Q) cp -r html/wifi/*.html html_compressed/wifi;
endif

ifeq (,$(findstring mqtt,$(MODULES)))
$(Q) rm -rf html_compressed/mqtt.html
$(Q) rm -rf html_compressed/mqtt.js
endif
$(Q) for file in `find html_compressed -type f -name "*.htm*"`; do \

$(Q) for file in `$(FIND) html_compressed -type f -name "*.htm*"`; do \
cat html_compressed/head- $$file >$${file}-; \
mv $$file- $$file; \
done
$(Q) rm html_compressed/head-
$(Q) cd html_compressed; find . \! -name \*- | ../espfs/mkespfsimage/mkespfsimage > ../build/espfs.img; cd ..;
$(Q) echo "Compressing assets into espfs.img with Gzip. This may take a while..."
$(Q) cd html_compressed; $(FIND) . \! -name \*- | ../espfs/mkespfsimage/mkespfsimage > ../build/espfs.img; cd ..;
$(Q) ls -sl build/espfs.img
$(Q) cd build; $(OBJCP) -I binary -O elf32-xtensa-le -B xtensa --rename-section .data=.espfs \
espfs.img espfs_img.o; cd ..
Expand All @@ -483,7 +497,7 @@ release: all
$(Q) egrep -a 'esp-link [a-z0-9.]+ - 201' $(FW_BASE)/user1.bin | cut -b 1-80
$(Q) egrep -a 'esp-link [a-z0-9.]+ - 201' $(FW_BASE)/user2.bin | cut -b 1-80
$(Q) cp $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin $(SDK_BASE)/bin/blank.bin \
"$(SDK_BASE)/bin/boot_v1.6.bin" "$(SDK_BASE)/bin/esp_init_data_default.bin" \
"$(BOOTFILE)" "$(SDK_BASE)/bin/esp_init_data_default.bin" \
wiflash avrflash release/esp-link-$(BRANCH)
$(Q) tar zcf esp-link-$(BRANCH)-$(SHA).tgz -C release esp-link-$(BRANCH)
$(Q) echo "Release file: esp-link-$(BRANCH)-$(SHA).tgz"
Expand All @@ -494,12 +508,12 @@ docker:
clean:
$(Q) rm -f $(APP_AR)
$(Q) rm -f $(TARGET_OUT)
$(Q) find $(BUILD_BASE) -type f | xargs rm -f
$(Q) $(FIND) $(BUILD_BASE) -type f | xargs rm -f
$(Q) make -C espfs/mkespfsimage/ clean
$(Q) rm -rf $(FW_BASE)
$(Q) rm -f webpages.espfs
ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes")
$(Q) rm -rf html_compressed
endif

$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))
$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ From there, more advanced steps are:

### Serial bridge

Note that the default ports of 23 & 2323 may be changed via the webinterface.

In order to connect through the esp-link to a microcontroller use port 23. For example,
on linux you can use `nc esp-hostname 23` or `telnet esp-hostname 23`.

Expand Down
2 changes: 1 addition & 1 deletion esp-link/cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ int ICACHE_FLASH_ATTR printGlobalInfo(char *buff, int buflen, char *token) {

extern char *esp_link_version; // in user_main.c

int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) {
int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) { //This is where we can modify the navigation that is auto generated
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
char buff[1024];
// don't use jsonHeader so the response does get cached
Expand Down
1 change: 0 additions & 1 deletion esp-link/cgipins.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <esp8266.h>
#include "cgi.h"
#include "espfs.h"
Expand Down
98 changes: 98 additions & 0 deletions esp-link/cgitelnet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <esp8266.h>
#include "cgi.h"
#include "config.h"
#include "serbridge.h"

// Cgi to return choice of Telnet ports
int ICACHE_FLASH_ATTR cgiTelnetGet(HttpdConnData *connData) {
char buff[80];

if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted

int len;

os_printf("Current telnet ports: port0=%d port1=%d\n",
flashConfig.telnet_port0, flashConfig.telnet_port1);

len = os_sprintf(buff,
"{ \"port0\": \"%d\", \"port1\": \"%d\" }",
flashConfig.telnet_port0, flashConfig.telnet_port1);

jsonHeader(connData, 200);
httpdSend(connData, buff, len);

return HTTPD_CGI_DONE;
}

// Cgi to change choice of Telnet ports
int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) {
char buf[80];

if (connData->conn==NULL) {
return HTTPD_CGI_DONE; // Connection aborted
}

int8_t ok = 0;
uint16_t port0, port1;
ok |= getUInt16Arg(connData, "port0", &port0);
ok |= getUInt16Arg(connData, "port1", &port1);

if (ok <= 0) { //If we get at least one good value, this should be >= 1
ets_sprintf(buf, "Unable to fetch telnet ports.\n Received: port0=%d port1=%d\n",
flashConfig.telnet_port0, flashConfig.telnet_port1);
os_printf(buf);
errorResponse(connData, 400, buf);
return HTTPD_CGI_DONE;
}

if (ok > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I heaven't dealt with the ajax stuff in a while and forgotten everything (oops), but I think you're gonna get one port at a time when you fill out one input field and hit enter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. Ill modify to have it check the flashconfig variables.

// fill both port variables from flash or ajax provided value
if (!port0) port0 = flashConfig.telnet_port0;
if (!port1) port1 = flashConfig.telnet_port1;

// check whether ports are different
if (port0 == port1) {
os_sprintf(buf, "Ports cannot be the same.\n Tried to set: port0=%d port1=%d\n",
flashConfig.telnet_port0, flashConfig.telnet_port1);
os_printf(buf);
errorResponse(connData, 400, buf);
return HTTPD_CGI_DONE;
}

// we're good, set flashconfig
flashConfig.telnet_port0 = port0;
flashConfig.telnet_port1 = port1;
os_printf("Telnet ports changed: port0=%d port1=%d\n",
flashConfig.telnet_port0, flashConfig.telnet_port1);

// save to flash
if (configSave()) {
httpdStartResponse(connData, 204);
httpdEndHeaders(connData);
} else {
httpdStartResponse(connData, 500);
httpdEndHeaders(connData);
httpdSend(connData, "Failed to save config", -1);
}

// apply the changes
serbridgeInit();
serbridgeStart(0, flashConfig.telnet_port0, flashDefault.telnet_port0mode);
serbridgeStart(1, flashConfig.telnet_port1, flashDefault.telnet_port1mode);

}

return HTTPD_CGI_DONE;
}

int ICACHE_FLASH_ATTR cgiTelnet(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
if (connData->requestType == HTTPD_METHOD_GET) {
return cgiTelnetGet(connData);
} else if (connData->requestType == HTTPD_METHOD_POST) {
return cgiTelnetSet(connData);
} else {
jsonHeader(connData, 404);
return HTTPD_CGI_DONE;
}
}
8 changes: 8 additions & 0 deletions esp-link/cgitelnet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef CGITELNET_H
#define CGITELNET_H

#include "httpd.h"

int cgiTelnet(HttpdConnData *connData);

#endif // CGITELNET_H
7 changes: 7 additions & 0 deletions esp-link/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ FlashConfig flashDefault = {
.data_bits = EIGHT_BITS,
.parity = NONE_BITS,
.stop_bits = ONE_STOP_BIT,
.telnet_port0 = 23,
.telnet_port1 = 2323,
.telnet_port0mode = 0,
.telnet_port1mode = 0,
};

typedef union {
Expand Down Expand Up @@ -161,6 +165,9 @@ bool ICACHE_FLASH_ATTR configRestore(void) {
flashConfig.parity = flashDefault.parity;
flashConfig.stop_bits = flashDefault.stop_bits;
}

if (flashConfig.telnet_port0 == 0) { flashConfig.telnet_port0 = flashDefault.telnet_port0; }
if (flashConfig.telnet_port1 == 0) { flashConfig.telnet_port1 = flashDefault.telnet_port1; }
return true;
}

Expand Down
7 changes: 6 additions & 1 deletion esp-link/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ typedef struct {
char hostname[32]; // if using DHCP
uint32_t staticip, netmask, gateway; // using DHCP if staticip==0
uint8_t log_mode; // UART log debug mode
uint8_t swap_uart; // swap uart0 to gpio 13&15
uint8_t swap_uart; // swap uart0 to gpio 13&15
uint8_t tcp_enable, rssi_enable; // TCP client settings
char api_key[48]; // RSSI submission API key (Grovestreams for now)
uint8_t slip_enable, mqtt_enable, // SLIP protocol, MQTT client
Expand Down Expand Up @@ -41,8 +41,13 @@ typedef struct {
int8_t data_bits;
int8_t parity;
int8_t stop_bits;
uint16_t telnet_port0, // Telnet port settings
telnet_port1;
int8_t telnet_port0mode,
telnet_port1mode;
} FlashConfig;
extern FlashConfig flashConfig;
extern FlashConfig flashDefault;

bool configSave(void);
bool configRestore(void);
Expand Down
Loading