This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void loop() { | |
| mqttclient.loop(); | |
| char* value; | |
| reading = digitalRead(inPin); // read the button state | |
| // if the input just went from LOW and HIGH and we've waited long enough to ignore | |
| // any noise on the circuit, toggle the output pin and remember the time | |
| if (reading == HIGH && previous == LOW && millis() - time > debounce) { | |
| if (state == LOW) { | |
| Serial.println("[PHYSICAL] Led turned on"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* MQTT server connection */ | |
| void lelylanConnection() { | |
| // add reconnection logics | |
| if (!client.connected()) { | |
| client = cc3000.connectTCP(server.ip, 1883); | |
| } | |
| // did that last thing work? sweet, let's do something | |
| if(client.connected()) { | |
| if (mqttclient.connect(clientId, deviceId, deviceSecret)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lelylanConnection(); // MQTT server connection | |
| pinMode(inPin, INPUT); // button pin setup | |
| pinMode(outPin, OUTPUT); // led pin setup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Serial.println(F("[CC3000]Init the WiFi connection\n")); | |
| if (!cc3000.begin()) { | |
| Serial.println(F("[CC3000] Fail init CC3000")); | |
| for(;;); | |
| } | |
| Serial.println(F("[CC3000] Deleting old profiles\n")); | |
| if (!cc3000.deleteProfiles()) { | |
| Serial.println(F("[CC3000] Fail deleting old profiles")); | |
| while(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int inPin = 5; // button | |
| int outPin = 7; // led |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Adafruit_CC3000.h> | |
| #include <ccspi.h> | |
| #include <SPI.h> | |
| #include <cc3000_PubSubClient.h> | |
| // These are the interrupt and control pins | |
| #define ADAFRUIT_CC3000_IRQ 2 | |
| #define ADAFRUIT_CC3000_VBAT A3 | |
| #define ADAFRUIT_CC3000_CS 8 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void _mqttClient_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { | |
| var messageString = new String(Encoding.UTF8.GetChars(e.Message)); | |
| this._ledOnBoard.Write(messageString.IndexOf("on") > 0); | |
| LelylanPublish(messageString.IndexOf("on") > 0 ? "on" : "off"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (_mqttClient.IsConnected) return; | |
| // register to message publish/subscribe | |
| _mqttClient.MqttMsgSubscribed += _mqttClient_MqttMsgSubscribed; | |
| _mqttClient.MqttMsgUnsubscribed += _mqttClient_MqttMsgUnsubscribed; | |
| _mqttClient.MqttMsgPublishReceived += _mqttClient_MqttMsgPublishReceived; | |
| _mqttClient.MqttMsgPublished += _mqttClient_MqttMsgPublished; | |
| _mqttClient.MqttMsgDisconnected += _mqttClient_MqttMsgDisconnected; | |
| // connection to lelylan MQTT server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void RunLightMonitor() { | |
| // Get onboard led reference | |
| this._ledOnBoard = new OutputPort(Pins.ONBOARD_LED, false); | |
| while (true) { | |
| LelylanConnection(); | |
| // read onboard led status | |
| bool ledStatus = this._ledOnBoard.Read(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public Controller() { | |
| // Init Client ID | |
| _clientId = Guid.NewGuid().ToString(); | |
| if (_clientId.Length > 20) | |
| _clientId = _clientId.Substring(_clientId.Length - 20, 20); | |
| // create client instance | |
| _mqttClient = new MqttClient(IPAddress.Parse(LelylanCore.MqttBrokerAddress)); | |
| } |