Skip to content

Commit

Permalink
v0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
xuefengedu authored Jun 20, 2019
1 parent 02fb43a commit 70e2f92
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,29 @@ if (esp01.connectToWiFiRouter("myRouterSSID", "password")) {
basic.showIcon(IconNames.No)
}
esp01.setupAPServer("myAPSSID", "password")
basic.forever(function () {
esp01.serveWebHTML(true)
while(true)
{
httpResult = esp01.getAPWebRequest()
pass = 0
if (httpResult == "") {
pass = 1
pins.digitalWritePin(DigitalPin.P0, 1)
pins.digitalWritePin(DigitalPin.P0, 1 - pins.digitalReadPin(DigitalPin.P0))
} else if (httpResult == "LED1") {
pass = 1
pins.digitalWritePin(DigitalPin.P8, 1)
pins.digitalWritePin(DigitalPin.P8, 1 - pins.digitalReadPin(DigitalPin.P8))
} else if (httpResult == "LED2") {
pass = 1
pins.digitalWritePin(DigitalPin.P16, 1)
pins.digitalWritePin(DigitalPin.P16, 1 - pins.digitalReadPin(DigitalPin.P16))
} else if (httpResult == "LED3") {
pass = 1
pins.digitalWritePin(DigitalPin.P10, 1 - pins.digitalReadPin(DigitalPin.P10))
} else if (httpResult == "LED4") {
pass = 1
pins.digitalWritePin(DigitalPin.P12, 1 - pins.digitalReadPin(DigitalPin.P12))
}
esp01.serveWebHTML(pass == 1)
})
}
input.onButtonPressed(Button.A, function () {
basic.showString(esp01.newline())
})
Expand Down
17 changes: 10 additions & 7 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace esp01 {
result = true
break
}
if (input.runningTime() - time > 300000) break
if (input.runningTime() - time > 30000) break
}
return result
}
Expand Down Expand Up @@ -74,10 +74,10 @@ namespace esp01 {
export function setupEsp01(TXPin: SerialPin = SerialPin.P1, RXPin: SerialPin = SerialPin.P2): void {
serial.redirect(TXPin, RXPin, BaudRate.BaudRate115200)
basic.pause(100)
// Restart module:
sendATCommand("AT+RST", 2000)
// WIFI mode = Station mode (client) + AP Server:
sendATCommand("AT+CWMODE=3", 5000)
// Restart module:
sendATCommand("AT+RST", 2000)
}

/**
Expand All @@ -92,7 +92,8 @@ namespace esp01 {
// Connect to AP:
sendATCommand("AT+CWJAP=\"" + ssid + "\",\"" + password + "\"", 6000)
let result: boolean = wait_for_response("OK")
if (!result) control.reset()
// don't reset, reset will hang here.
// if (!result) control.reset()
return result
}

Expand Down Expand Up @@ -124,6 +125,8 @@ namespace esp01 {
sendATCommand("AT+CIPSERVER=1,80")
// display IP (you'll need this in STA mode; in AP mode it would be default 192.168.4.1)
//sendATCommand("AT+CIFSR")
// Restart module:
sendATCommand("AT+RST", 2000)
}

// generate HTML
Expand All @@ -149,8 +152,8 @@ namespace esp01 {
html += "<br>"
// generate status text
if (normal) {
for (let i = 0; i < 16; ++i) {
const index=15-i;
for (let i = 0; i < 4; ++i) {
const index=3-i;
const a=LED_status >> index;
if((a & 1)==0)
{
Expand Down Expand Up @@ -202,7 +205,7 @@ namespace esp01 {
getCommand = serial_str.substr(GET_pos + 5, (HTTP_pos - 1) - (GET_pos + 5))
break;
}
if (input.runningTime() - time > 300000) {
if (input.runningTime() - time > 30000) {
getCommand = "TIMEOUT"
break
}
Expand Down
2 changes: 1 addition & 1 deletion pxt.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esp01",
"version": "0.0.6",
"version": "0.0.7",
"description": "esp01 for micro:bit",
"license": "MIT",
"dependencies": {
Expand Down
18 changes: 13 additions & 5 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@ if (esp01.connectToWiFiRouter("myRouterSSID", "password")) {
basic.showIcon(IconNames.No)
}
esp01.setupAPServer("myAPSSID", "password")
basic.forever(function () {
esp01.serveWebHTML(true)
while(true)
{
httpResult = esp01.getAPWebRequest()
pass = 0
if (httpResult == "") {
pass = 1
pins.digitalWritePin(DigitalPin.P0, 1)
pins.digitalWritePin(DigitalPin.P0, 1 - pins.digitalReadPin(DigitalPin.P0))
} else if (httpResult == "LED1") {
pass = 1
pins.digitalWritePin(DigitalPin.P8, 1)
pins.digitalWritePin(DigitalPin.P8, 1 - pins.digitalReadPin(DigitalPin.P8))
} else if (httpResult == "LED2") {
pass = 1
pins.digitalWritePin(DigitalPin.P16, 1)
pins.digitalWritePin(DigitalPin.P16, 1 - pins.digitalReadPin(DigitalPin.P16))
} else if (httpResult == "LED3") {
pass = 1
pins.digitalWritePin(DigitalPin.P10, 1 - pins.digitalReadPin(DigitalPin.P10))
} else if (httpResult == "LED4") {
pass = 1
pins.digitalWritePin(DigitalPin.P12, 1 - pins.digitalReadPin(DigitalPin.P12))
}
esp01.serveWebHTML(pass == 1)
})
}
input.onButtonPressed(Button.A, function () {
basic.showString(esp01.newline())
})
Expand Down

0 comments on commit 70e2f92

Please sign in to comment.