Skip to content

Commit

Permalink
nodemcu
Browse files Browse the repository at this point in the history
  • Loading branch information
filipdulic committed Aug 7, 2016
1 parent d901bfa commit e5f8297
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
42 changes: 28 additions & 14 deletions examples/Echo/Echo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,38 @@ SoftwareSerial sSerial(7, 6);

void setup() {
lcd.begin(84, 48);

// Write a piece of text on the first line...
lcd.setCursor(0, 0);
lcd.print("Awaiting input: ");

sSerial.begin(9600);
lcd.print("DESCON 2016");
lcd.setCursor(0, 1);
lcd.print("Badger");
delay(2000);
}

String sAddr;
String sBuffer;
bool start = false;
void loop() {
// Just to show the program is alive...
static int counter = 0;

lcd.setCursor(0, 1);



if(sSerial.available()) {
lcd.print(sSerial.readString());
tone(12,4100,500);
sBuffer = sSerial.readString();

if(sBuffer.substring(0,9) == "Ip Addr: " && start==false){
sAddr = sBuffer.substring(10);
lcd.setCursor(0, 3);
lcd.print(sAddr);
start = true;
}
else{
lcd.clear();
if(sAddr.length()!=0){
lcd.setCursor(0, 0);
lcd.print(sAddr);
}
lcd.setCursor(0, 1);
lcd.print(sBuffer);
}
}

delay(200);
}


19 changes: 19 additions & 0 deletions examples/Echo/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- init.lua --


-- Global Variables (Modify for your network)
ssid = "strawberrybush"
pass = ""

-- Configure Wireless Internet
wifi.setmode(wifi.STATION)
-- print('set mode=STATION (mode='..wifi.getmode()..')\n')
-- print('MAC Address: ',wifi.sta.getmac())
-- print('Chip ID: ',node.chipid())
-- print('Heap Size: ',node.heap(),'\n')
-- wifi config start
wifi.sta.config(ssid,pass)
-- wifi config end

-- Run the main file
dofile("main.lua")
17 changes: 17 additions & 0 deletions examples/Echo/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tmr.alarm(0, 5000, 1, function()
if wifi.sta.getip() == nil then
print("Connecting to AP...\n")
else
ip, nm, gw=wifi.sta.getip()
print("Ip Addr: ",ip)
tmr.stop(0)
end
end)

srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
print(payload)
end)
conn:on("sent",function(conn) conn:close() end)
end)

0 comments on commit e5f8297

Please sign in to comment.