ESP8266 plot example

ESP sending data to RoboRemo plot item

ESP8266 plot example

This is a simple example about sending data from ESP8266 to RoboRemo plot item.

Materials needed:
- ESP8266 module running NodeMCU
- Android phone with RoboRemo app installed

Introduction

This is a simple demo showing how to send data to plot item.
It can be easily modified to send some useful data like the reading of a temperature sensor.
It was tested with NodeMCU 0.9.5 build 20150214 powered by Lua 5.1.4, but should work with other versions as well.

Steps:

1.
Write this init.lua script to your ESP8266:

wifi.setmode(wifi.SOFTAP)

cfg={}
cfg.ssid="mywifi"
cfg.pwd="qwerty123"

cfg.ip="192.168.0.1"
cfg.netmask="255.255.255.0"
cfg.gateway="192.168.0.1"

port = 9876

wifi.ap.setip(cfg)
wifi.ap.config(cfg)

function stringStarts(a,b)
    return string.sub(a,1,string.len(b))==b
end

function stringEnds(a,b)
   return b=='' or string.sub(a,-string.len(b))==b
end



on=0
val=0
cmd=""

function exeCmd(st) 
    if stringStarts(st, "on") then on=1 end  
    if stringStarts(st, "off") then on=0 end   
end


function receiveData(conn, data)
    cmd = cmd .. data

    local a, b = string.find(cmd, "\n", 1, true)   
    while a do
        exeCmd( string.sub(cmd, 1, a-1) )
        cmd = string.sub(cmd, a+1, string.len(cmd))
        a, b = string.find(cmd, "\n", 1, true)
    end 
end


print("ESP8266 to RoboRemo plot")
print("SSID: " .. cfg.ssid .. "  PASS: " .. cfg.pwd)
print("RoboRemo app must connect to " .. cfg.ip .. ":" .. port)

srv=net.createServer(net.TCP, 28800) 
srv:listen(port,function(conn)
    print("RoboRemo connected")
     
    conn:on("receive",receiveData)  
    
    conn:on("disconnection",function(c) 
        print("RoboRemo disconnected")
    end)
    
    tmr.stop(1)
    tmr.alarm(1,50,1,function() -- send to plot every 50 ms
        if on==1 then
          conn:send("val " .. val .. "\n")
          val=val+1
          if val==20 then val=0 end
        end
    end)

end)

2.
Restart your ESP8266.

3.
Activate WiFi on your phone or tablet and connect to "mywifi" with password "qwerty123"

4.
Download RoboRemo interface file:

plot-example.interface

Copy the interface file to your Android device, then import in RoboRemo using menu -> interface -> import.

5.
Open RoboRemo.

6.
Click button "connect"

7.
Click button "on"

8.
Enjoy :)

9.
Modify the project to read a sensor and plot its data.

10.
Make YouTube video about it.