Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * V_TEXT example with Domoticz (c) 2018 GizMoCuz
- *
- * Note this is some quick code to demonstrate the workings
- *
- * When the node has started and correctly been found by the controller,
- * you should have two new text sensors in Domoticz (if not, enable accept new hardware!)
- * Those two sensors have an IDX, for example 1063 and 1063
- * To update the first line call something line http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=1063&nvalue=0&svalue=Hello%20Line%201
- */
- // Enable debug prints to serial monitor
- //#define MY_DEBUG
- // Enable and select radio type attached
- #define MY_RADIO_NRF24
- //#define MY_RADIO_NRF5_ESB
- //#define MY_RADIO_RFM69
- //#define MY_RADIO_RFM95
- #define MY_NODE_ID 253
- #include <SPI.h>
- #include <MySensors.h>
- #include <LiquidCrystal_I2C.h>
- #include <Wire.h>
- #define UV_SENSOR_ANALOG_PIN 0
- const byte LCD1_CHILD_ID = 8 ; // LCD line 1
- const byte LCD2_CHILD_ID = 9 ; // LCD line 2
- char lastLCD1[21] = "Line1 - first"; // define & init before first receive
- char lastLCD2[21] = "Line2 - second";
- uint32_t ActTime = 0;
- // timers for loop delays
- unsigned long lastUpdate=0, lastRequest=0;
- // Initialize messages for sensor network
- MyMessage textMsg(0, V_TEXT);
- #define I2C_ADDR 0x27
- //---(Following are the PCF8574 pin assignments to LCD connections )----
- // This are different than earlier/different I2C LCD displays
- #define LCD_WIDTH 20
- #define LCD_HEIGHT 4
- LiquidCrystal_I2C lcd(I2C_ADDR, LCD_WIDTH, LCD_HEIGHT);
- void setup(void){
- // ** LCD display **
- Wire.begin(); // I2C
- lcd.begin(); // LCD 2 lines * 16 char.
- lcd.setBacklight(HIGH);
- lcd.setCursor(0, 0);
- Serial.begin(115200);
- Serial.println("Sensor Started");
- }
- void presentation()
- {
- // Send the sketch version information to the gateway and Controller
- sendSketchInfo("V_TEXT LCD Sensor", "1.1");
- present(LCD1_CHILD_ID, S_INFO, "Text Line 1");
- present(LCD2_CHILD_ID, S_INFO, "Text Line 2");
- // Initializations
- requestTime(); // get the time from controller (handled by receiveTime)
- request(LCD1_CHILD_ID, V_TEXT, 0); // request latest value from controller
- request(LCD2_CHILD_ID, V_TEXT, 0); // request latest value from controller
- }
- void loop()
- {
- // timer for loop delays
- unsigned long now = millis();
- // request time every 10 seconds from controller
- if (now-lastRequest > 10*1000)
- {
- requestTime();
- lastRequest = now;
- }
- // Update display every second
- if (now-lastUpdate > 1000) {
- LCD_local_display();
- lastUpdate = now;
- }
- }
- // This is called when a new time value was received
- void receiveTime(uint32_t controllerTime)
- {
- Serial.print("Time value received: ");
- Serial.println(controllerTime);
- ActTime = controllerTime;
- }
- void LCD_local_display()
- {
- // take care of LCD display information
- char buf[LCD_WIDTH]; // temp buffer for max LCD_WIDTH+1 char display
- if (ActTime!=0) {
- // start with location & time on first line
- //snprintf(buf, sizeof buf, "%02d:%02d:%02d %02d-%02d", hour(ActTime), minute(), second(), day(), month());
- snprintf(buf, sizeof buf, "%ld,%02d:%02d:%02d %02d-%02d", ActTime, 16, 32, 59, 10, 5);
- lcd.setCursor(0, 0);
- lcd.print(buf);
- }
- lcd.setCursor(0, 2);
- lcd.print(lastLCD1); // second line is text value from controller
- lcd.setCursor(0, 3);
- lcd.print(lastLCD2);
- }
- void receive(const MyMessage &message)
- {
- if (message.type!=V_TEXT) // Text messages only
- return;
- // Write some debug info
- Serial.print("Message: ");
- Serial.print(message.sensor);
- Serial.print(", Message: ");
- Serial.println(message.getString());
- if (message.sensor == LCD1_CHILD_ID ) {
- snprintf(lastLCD1, sizeof(lastLCD1), "%20s", message.getString()); // load text into LCD string
- }
- else if (message.sensor == LCD2_CHILD_ID) {
- snprintf(lastLCD2, sizeof(lastLCD2), "%20s", message.getString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment