Synthomir goes online with esp8266 wifi modul

Synthomir goes online with esp8266 wifi modul

ESP82660000DSCF5999DSCF6000DSCF6001

This version did not work with putty, and linux, working from windows terminal
file.remove("init.lua")
file.open("init.lua","w")
file.writeline([[print("####################################################")]])
file.writeline([[print("Radiona ESP8266 module for Synthomir")]])
file.writeline([[print("Version: v0.1")]]) 
file.writeline([[print("Presented by.: Igor(Synthomir),Davor(Lua),Goran(ESP)")]]) 
file.writeline([[print("Wait for 5 sec for IP adress")]]) 
file.writeline([[print("Telnet to port 80, and send A to Blink LED")]])
file.writeline([[print("Blink is set to 1000 micro seconds, becouse it will be used as Synthomir button")]])
file.writeline([[print("####################################################")]])
file.writeline([[tmr.alarm(10000, 0, function() dofile("get_IP.lua") end )]])
file.close()
file.remove("get_IP.lua")
file.open("get_IP.lua","w") 
file.writeline([[print("Current IP is: ")]])
file.writeline([[print(wifi.sta.getip())]])
file.writeline([[tmr.alarm(1000, 0, function() dofile("start_Server.lua") end )]])
file.close()
file.remove("start_Server.lua")
file.open("start_Server.lua","w")
file.writeline([[dofile("blink_Led.lua")]])
file.writeline([[print("Starting server")]])
file.writeline([[print("Creating a server")]])
file.writeline([[print("Server listen on 80, if data received checks for letter A, if A is recieved LED blinks.")]])
file.writeline([[sv=net.createServer(net.TCP, 30)]])
file.writeline([[sv:listen(80,function(c)]])
file.writeline([[  c:on("receive", function(sck, pl) if (pl=="a") then dofile("TurnLedOn.lua") elseif (pl=="b") then dofile("TurnLedOff.lua") else  print("Caracter is not A, send A to blink LED") end end)]])
file.writeline([[  end)]])
file.writeline([[print("Server started")]])
file.close()
file.remove("TurnLedOn.lua")
file.open("TurnLedOn.lua","w")
file.writeline([[print("Setting GPIO4 to HIGH -- pin1")]])
file.writeline([[gpio.write(10, gpio.HIGH)]]) 
file.close()
file.remove("TurnLedOff.lua")
file.open("TurnLedOff.lua","w")
file.writeline([[print("Setting GPIO4 to LOW -- pin1")]])
file.writeline([[gpio.write(10, gpio.LOW)]]) 
file.close()
file.remove("blink_Led.lua")
file.open("blink_Led.lua","w")
file.writeline([[dofile("TurnLedOn.lua")]])
file.writeline([[for i=1,10000 do]])
file.writeline([[  tmr.wdclr()]])
file.writeline([[end]])
file.writeline([[dofile("TurnLedOff.lua")]])
file.close()
This version is working from putty, just type ON and press ENTER to turn led ON
file.remove("start_Server.lua")
file.open("start_Server.lua","w")
file.writeline([[dofile("blink_Led.lua")]])
file.writeline([[print("Starting server")]])
file.writeline([[sv=net.createServer(net.TCP, 30)]])
file.writeline([[sv:listen(80,function(c)]])
file.writeline([[  c:on("receive", function(sck, pl) print(pl)]])
file.writeline([[ if string.find (pl,"ON") then dofile ("TurnLedOn.lua") c:send("LED ON\n\r")]])
file.writeline([[ elseif string.find (pl,"OFF") then dofile ("TurnLedOff.lua") c:send("LED OFF\n\r")]])
file.writeline([[ else print("\n\r")]])
file.writeline([[ end]])
file.writeline([[ end)]])
file.writeline([[  c:send("Welcome to Synthomir server, type letter a to press button down, and letter b to relese button\n\r")]])
file.writeline([[  end)]])
file.writeline([[print("Server started")]])
file.close() 
on router with openwrt I have installed lua, and write a script that pings range of adress
ip_tables = {}
ip_tables_count = 0
for i=1,254 do
ping_success=os.execute('ping -c 1 -4 -w 1 10.254.221.' ..i.. '>/dev/null')
if (ping_success == 0) then
  ip_tables[ip_tables_count] = '10.254.221.' ..i
  ip_tables_count = ip_tables_count + 1
--  print("Pinging 10.254.221." ..i.. " success")
else
-- print("Pinging 10.254.221." ..i.. " failed")
end
end
print("There are " ..ip_tables_count.. " active clients")
for i=1,ip_tables_count do
os.execute("/scripts/blink_LED.sh")
end
ip_tables = {}
ip_tables_count = 0
and blinks no. of connected clients
printf "ON" | telnet 10.254.184.235 80
sleep 1
printf "OFF" | telnet 10.254.184.235 80
sleep 1
Processing sample is work in progress …
import processing.net.*;
import controlP5.*;

ControlP5 cp5;

boolean lEDStatus =  false;
Client c;

void setup() 
{
  size(200, 200);
  cp5 = new ControlP5(this);
  cp5.addButton("buttonA")
     .setPosition(50,50)
     .setImages(loadImage("Arrow-Left.png"), loadImage("Arrow-Right.png"), loadImage("Refresh.png"))
     .updateSize();
  frameRate(10); // Slow it down a little
  // Connect to the server's IP address and port
  c = new Client(this, "10.254.184.235", 80); // Replace with your server's IP and port
}
void draw() 
{
  // Receive data from server
  if (c.available() > 0) {
  
  }
}
public void controlEvent(ControlEvent theEvent) {
  println(theEvent.getController().getName());
if (lEDStatus){
      c.write("OFF" + "\n");
      lEDStatus=false;
  }
  else{
      c.write("ON" + "\n");
      lEDStatus=true;  
    }
}

https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en
http://scargill.wordpress.com/
http://esp8266.ru/wp-content/uploads/esp8266-gpio.jpg
http://esp8266.ru/

Odgovori