-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinit.lua
More file actions
59 lines (49 loc) · 1.68 KB
/
init.lua
File metadata and controls
59 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
--
-- Created by IntelliJ IDEA.
-- User: jcrygier
-- Date: 2/5/16
-- Time: 1:28 PM
-- Example file to test some of the functionality of the simulator
--
-- Simulate SPI (APA102)
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_HIGH, 8, 1);
-- Simulate Blinky LED
local pinState = gpio.HIGH;
gpio.write(0, pinState);
tmr.alarm(0, 1000, tmr.ALARM_AUTO, function()
print("Triggered with state: " .. pinState);
if (pinState == gpio.HIGH) then
pinState = gpio.LOW;
spi.send(1, 0, 0, 0, 0); -- APA102 Start Frame
spi.send(1, 255, 0, 0, 0); -- APA102 Pixel 1 - Black
spi.send(1, 0, 0, 0, 0); -- APA102 End Frame
else
pinState = gpio.HIGH;
spi.send(1, 0, 0, 0, 0); -- APA102 Start Frame
spi.send(1, 255, 255, 255, 255); -- APA102 Pixel 1 - Brightest White
spi.send(1, 0, 0, 0, 0); -- APA102 End Frame
end
gpio.write(0, pinState);
end)
-- Simulate MQTT
m = mqtt.Client("Test-Client-ID", 120);
m:on("message", function(client, topic, data)
print("Message received on topic: " .. topic .. "\nData: " .. data);
end)
m:on("connect", function(client)
m:subscribe("temp/random", 0);
m:publish("temp/nodemcu-test", "This is a test", 0);
end)
m:connect("test.mosquitto.org", 1883, false, true, function(client)
print("Connected");
end)
-- Simulate starting a server
sv = net.createServer(net.TCP, 30)
-- server listens on 8080, if data received, print data to console and send "hello world" back to caller
sv:listen(8080, function(c)
c:on("receive", function(c, pl)
print(pl)
end)
c:send("hello world")
end)
print("Simulation Started");