ESP8266 IoT

From ElectroDragon Wiki
(Redirected from ESP IOT)

AI-Thinker AI-Link

  1. make sure you are using at least 1.2 version AT firmware (run cloud update first)
  2. Turn on the APP "AI-link" in your android cell phone
  3. enter the wifi SSID and password and click "start"
  • set on module
  1. set mode AT+CWMODE=1
  2. run command on the module to start
AT+CWSMARTSTART=0 
  1. now the serial monitor will show up the wifi SSID and password info and automatically connect it.
OK
SMART SUCCESS
SSID:TP-LINK_4226
PASSWORD:1234567890
  1. Try to make a ping test
AT+PING="www.baidu.com" 
+42
OK

Espressif ESP-Touch

  1. make sure you are using at least 1.2 version AT firmware (run cloud update first)
  2. Turn on the APP "smarthome" in your android cell phone
  3. click "smartlink" and enter wifi details then connect
  • Set on module
  1. AT+CWMODE=1
OK
  1. AT+CWSMARTSTART=1 // using mode 2, slower
OK
WIFI DISCONNECT
SMART SUCCESS
SSID:TP-LINK_4226
PASSWORD:1234567890
OK
WIFI CONNECTED
WIFI GOT IP
  1. Try to make a ping test
AT+PING="www.baidu.com" 
+42
OK

Wechat Air-Kiss

Smartlink mode

  • AT + CWSMARTSTART = 0 AI-LINK intelligent connections advantages: fast, the router is compatible with the best available in the phone is not connected to the case under the Wi-Fi configuration. Cons: Wi-Fi will cause the phone offline. Principle and current connection socket using the same small k.
  • AT + CWSMARTSTART = 1 ESP-TOUCH intelligent connection Advantages: Wi-Fi will not disconnect the phone Disadvantages: slow, very few router may have compatibility issues.
  • AT + CWSMARTSTART = 2 Airkiss intelligent connections advantages: support micro-channel hardware platform. Cons: Almost not own designs APP calls.

Lan service

  • AT+LANSTART

Cloud Send

  • AT+CIFSR make sure connect to internet
  • AT+CIPSTART="UDP","iot.ai-thinker.com",5001
  • AT+CLDSTART // cloud send start
  • AT+CLDSTOP // cloud send stop
  • AT+CIPMODE=1
  • AT+CIPSEND
  • {"type":"signin","name":"ai-thinker","password":"12345"}
  • {"type":"connect","from*:*ai-thinker","to*:*anyone","password*:*anyonePassword"}
  • {"type":"disconnect"}
  • {"type":"signout","name":"ai-thinker","password":"12345"}

Reference link

ESP Cloud Data

NodeMCU w/relayr

Data Logging Platform

MQTT

Cloudmqtt with NodeMCU

Cloudmqtt setup

m=mqtt.Client("nodemcu1",60,"swqzxzhr","9JMcxVeUNz3t")
m:connect("m11.cloudmqtt.com",19311,0,1)

Modified example code

-- test with cloudmqtt.com
m_dis={}

function dispatch(m,t,pl)
	if pl~=nil and m_dis[t] then
		m_dis[t](m,pl)
	end
end

function topic1func(m,pl)
	print("get1: "..pl)
end

function topic2func(m,pl)
	print("get2: "..pl)
end

m_dis["/topic1"]=topic1func
m_dis["/topic2"]=topic2func

-- Lua: mqtt.Client(clientid, keepalive, user, pass)
m=mqtt.Client("nodemcu1",60,"swqzxzhr","9JMcxVeUNz3t")

-- Lua: mqtt:connect( host, port, secure, auto_reconnect, function(client) )
m:connect("m11.cloudmqtt.com",19311,0,1)

-- ON callback event "connect", subscribe to topic and start the first publish
m:on("connect",function(m) 
	print("connection "..node.heap()) 
	m:subscribe("/topic1",0,function(m) print("sub done") end)
	m:subscribe("/topic2",0,function(m) print("sub done") end)
	m:publish("/topic1","hello112",0,0) m:publish("/topic2","world211",0,0)
	end )

-- ON callback event "offline"
m:on("offline", function(conn)
    print("disconnect to broker...")
    print(node.heap())
end)

-- ON callback event "message", and print on NodeMCU monitor
m:on("message",dispatch )

-- intervally publish the time
tmr.alarm(0,10000,1,function() local pl = "time: "..tmr.time() 
	m:publish("/topic2",pl,0,0)
	end)

More reference

  • test.mosquitto.org