Share My Creation Android smart watch ZGPAX and WIFI low cost module ESP8266 for SMART HOME

I write little app for Android watch (or smartphone) and esp8266.It's not a bad thing for the smart home.Сost module ~3,5$!!!
module ESP8266
09b8d5.jpg


Corresponding Interface:
SDIO 2.0, SPI, UART
32-pin QFN package
Integrated RF switch, balun, 24dBm PA, DCXO, and PMU
Integrated RISC processor, on-chip memory and external memory interfaces
Integrated MAC/baseband processors
Quality of Service management
I2S interface for high fidelity audio applications
On-chip low-dropout linear regulators for all internal supplies
Proprietary spurious-free clock generation architecture
Integrated WEP, TKIP, AES, and WAPI engines

Specification:
802.11 b/g/n
Wi-Fi Direct (P2P), soft-AP
Integrated TCP/IP protocol stack
Integrated TR switch, balun, LNA, power amplifier and matching network
Integrated PLLs, regulators, DCXO and power management units
+19.5dBm output power in 802.11b mode
Power down leakage current of <10uA
Integrated low power 32-bit CPU could be used as application processor
SDIO 1.1/2.0, SPI, UART
STBC, 1×1 MIMO, 2×1 MIMO
A-MPDU & A-MSDU aggregation & 0.4ms guard interval
Wake up and transmit packets in < 2ms
Standby power consumption of < 1.0mW (DTIM3)




That it is able my app to :
- read the temperature DS18B20
- turn ON/OFF relay (button or voice)
- considered on time relay (save flash memory)
how it looks like:
main.png

setting:
main1.png


I made a simple development board

plat.jpg


PHOTO
watch.jpg


I write LUA SCRIPT UDP SERVER for module

B4X:
counter=0
GCOUNTER=0
port=7777
stled=0
pinled=9

pin = 8
ow.setup(pin)
TEMP=0
counter=0
lasttemp=-999



function Init()
print("LT205WF V1.0")
pinled=9
gpio.mode(pinled, gpio.OUTPUT)
gpio.write(pinled, gpio.LOW)
if file.open("ltimer.log", "r")== nil then
file.remove("ltimer.log")
file.open("ltimer.log", "w")
file.writeline(GCOUNTER)
file.close()
else
GCOUNTER=file.readline()
file.close()
end
end


function bxor(a,b)
local r = 0
for i = 0, 31 do
if ( a % 2 + b % 2 == 1 ) then
r = r + 2^i
end
a = a / 2
b = b / 2
end
return r
end

function ShowTemp()
getTemp()
t1 = lasttemp / 10000
t2 = (lasttemp >= 0 and lasttemp % 10000) or (10000 - lasttemp % 10000)
t2 =t2 / 100
--print("!TEMP" .. t1 .. "." .. string.format("%2d", t2) .."\r")
TEMP= t1 .. "." .. string.format("%d", t2)
--print(TEMP)
end

function getTemp()
addr = ow.reset_search(pin)
repeat
tmr.wdclr()

if (addr ~= nil) then
crc = ow.crc8(string.sub(addr,1,7))
if (crc == addr:byte(8)) then
if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then
ow.reset(pin)
ow.select(pin, addr)
ow.write(pin, 0x44, 1)
tmr.delay(1000000)
present = ow.reset(pin)
ow.select(pin, addr)
ow.write(pin,0xBE, 1)
data = nil
data = string.char(ow.read(pin))
for i = 1, 8 do
data = data .. string.char(ow.read(pin))
end
crc = ow.crc8(string.sub(data,1,8))
if (crc == data:byte(9)) then
t = (data:byte(1) + data:byte(2) * 256)
if (t > 32768) then
t = (bxor(t, 0xffff)) + 1
t = (-1) * t
end
t = t * 625
lasttemp = t
--print("Last temp: " .. lasttemp)
end
tmr.wdclr()
end
end
end
addr = ow.search(pin)
until(addr == nil)
end

----------------MAIN FUNCTION-----------------------
Init()
srv=net.createServer(net.UDP)
srv:on("receive", function(srv, pl)
print(pl)
if pl=="!SetR1_1\r" then
gpio.write(pinled, gpio.HIGH)
stled=1
counter=0
srv:send("!LEDON\r")
end
if pl=="!SetR0_1\r" then
gpio.write(pinled, gpio.LOW)
stled=0
srv:send("!LEDOFF\r")
file.open("ltimer.log", "w")
file.write(GCOUNTER)
file.close()

end

if pl=="!GetR_1\r" then
if stled ==1 then
srv:send("!LEDON\r")
else
srv:send("!LEDOFF\r")
end
end
if pl=="!GetCount\r" then
srv:send("!COUNT "..counter.."\r")
end
if pl=="!GetGcount\r" then
srv:send("!GCOUNT "..GCOUNTER.."\r")
end
if pl=="!GetC_1\r" then
print(ShowTemp())
srv:send("!TEMP"..TEMP.."\r")
end
if pl=="!ClrCount\r" then
GCOUNTER=0
srv:send("!GCOUNT=0\r")
end
if pl=="!GetIp\r" then
srv:send("!IP "..wifi.sta.getip().."\r")
end

end)
srv:listen(port)
uart.on("data",function(data)srv:send(data)end, 1)
--timer 1
tmr.alarm(2,60000,1, function()
if stled==1 then
counter=counter+1
GCOUNTER=GCOUNTER+1
--print(counter)
end
end )


 

Attachments

  • main.png
    main.png
    32.3 KB · Views: 9,097
  • andrele.zip
    280.3 KB · Views: 1,159
Last edited:

XorAndOr

Active Member
Licensed User
Longtime User
Hi, i installed the apk temperature and working properly. Kindly could have code B4A reported to the program ?, because I did some tests with httputils2 and module esp8266 and can only communicate with the sending of the instructions, but I have nothing in reception. Thank You. excuse the translation with google !.

Solved with B4A SOCKET.:)
 
Last edited:

Ambro

New Member
Good day,
I am an Italian radio Ham and I am facing to the esp8266 for the first times.
I would like to load a program that allows me to send the UART data to a web page accesible from the net.
I alredy have a MCU that send out uart data at 9600 8 n 1 to the ESP but still not able to send those data on the web: I will like to see data on my smart phone too.
Is this feasible ?
Could you please help me in describing the procedure in a step by step mode ?
Thanks a lot for the help.
Rehards,
Ambro
 

freedom2000

Well-Known Member
Licensed User
Longtime User
HI Italia !

Jump to this link : https://github.com/esp8266/arduino
install the full arduino package

Then go to the menu, examples/ESP8266Webserver and find the "hello client" sketch

For sure you will find a lot of other examples. Try it's easy

B4X:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

const char* ssid = "........";
const char* password = "........";

ESP8266WebServer server(80);

const int led = 13;

void handleRoot() {
  digitalWrite(led, 1);
  server.send(200, "text/plain", "hello from esp8266!");
  digitalWrite(led, 0);
}

void handleNotFound(){
  digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}

void setup(void){
  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

  server.on("/inline", [](){
    server.send(200, "text/plain", "this works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
}
 
Top