[Solved] Add temperature to image

Forum for questions and support relating to the 1.30.x releases only.
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Add temperature to image

Post by rockedge »

your code looks okay.
Is zmTrigger.pl running?
Can you test the string by a telnet connection to port 6802 and sending your command string manually like

Code: Select all

telnet localhost 6802
2|show|255|||22.8 °C 73.0 °F
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

Re: Add temperature to image

Post by Sigge »

I think my zoneminder is somehow screwed up. Just reinstalled it but still lots of log entry's.

Maybe my monitor never gets created?

the logs:

Code: Select all


DATE/TIME
COMPONENT	SERVER	PID	LEVEL	MESSAGE	FILE	LINE
2017-01-18 00:10:12.421181	zmc_m1		9437	ERR	Unable to open input rtsp://192.168.1.160:554/tcp_live/ch0_0 due to: Operation now in progress	zm_ffmpeg_camera.cpp	280
2017-01-18 00:10:10.903468	zmc_m1		9437	WAR	Unable to parse ffmpeg option 0 '', expecting key=value	zm_ffmpeg_camera.cpp	267
2017-01-18 00:10:01.901455	zmc_m1		9437	ERR	Unable to open input rtsp://192.168.1.160:554/tcp_live/ch0_0 due to: Operation now in progress	zm_ffmpeg_camera.cpp	280
2017-01-18 00:10:00.386476	zmc_m1		9437	WAR	Unable to parse ffmpeg option 0 '', expecting key=value	zm_ffmpeg_camera.cpp	267
2017-01-18 00:09:52.381501	zmc_m1		9437	ERR	Unable to open input rtsp://192.168.1.160:554/tcp_live/ch0_0 due to: Operation now in progress	zm_ffmpeg_camera.cpp	280
2017-01-18 00:09:50.873214	zmc_m1		9437	WAR	Unable to parse ffmpeg option 0 '', expecting key=value	zm_ffmpeg_camera.cpp	267
2017-01-18 00:09:41.871247	zmc_m1		9437	ERR	Unable to open input rtsp://192.168.1.160:554/tcp_live/ch0_0 due to: Operation now in progress	zm_ffmpeg_camera.cpp	280
2017-01-18 00:09:40.363190	zmc_m1		9437	WAR	Unable to parse ffmpeg option 0 '', expecting key=value	zm_ffmpeg_camera.cpp	267
2017-01-18 00:09:36.478240	zmtrigger		9230	WAR	Can't find monitor '1' for message '1|show|255|||22.8 °C 73.1 °F'	zmtrigger.pl	
2017-01-18 00:09:32.361308	zmc_m1		9437	ERR	Unable to open input rtsp://192.168.1.160:554/tcp_live/ch0_0 due to: Operation now in progress	zm_ffmpeg_camera.cpp	280
2017-01-18 00:09:30.844929	zmc_m1		9437	WAR	Unable to parse ffmpeg option 0 '', expecting key=value	zm_ffmpeg_camera.cpp	267
2017-01-18 00:09:21.840646	zmc_m1		9424	ERR	Unable to open input rtsp://192.168.1.160:554/tcp_live/ch0_0 due to: Operation now in progress	zm_ffmpeg_camera.cpp	280
2017-01-18 00:09:20.340980	zmdc		9190	WAR	Can't find process with command of 'zma -m 1'	zmdc.pl	
2017-01-18 00:09:20.330125	zmc_m1		9424	WAR	Unable to parse ffmpeg option 0 '', expecting key=value	zm_ffmpeg_camera.cpp	267
2017-01-18 00:09:20.328520	zmc_m1		9424	INF	Priming capture from rtsp://192.168.1.160:554/tcp_live/ch0_0	zm_ffmpeg_camera.cpp	104
2017-01-18 00:09:20.325538	zmc_m1		9424	INF	Starting Capture version 1.30.0	zmc.cpp	250
2017-01-18 00:09:20.253120	zmdc		9424	INF	'zmc -m 1' started at 17/01/18 00:09:20	zmdc.pl	
2017-01-18 00:09:20.253110	zmdc		9190	INF	'zmc -m 1' starting at 17/01/18 00:09:20, pid = 9424	zmdc.pl	
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

Re: Add temperature to image

Post by Sigge »

telnet
1|show|255|||22.8 °C 73.0 °F

gives me:
2017-01-18 00:17:39.128030 zmtrigger 9230 WAR Can't find monitor '1' for message '1|show|255|||22.8 °C 73.0 °F' zmtrigger.pl

it is one now.

Thanks
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Add temperature to image

Post by rockedge »

It does look like the camera never becomes a monitor. Perhaps ZoneMinder is OK and the camera URL is off and/or the camera is not configured correctly?
Can you see a camera stream?
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

Re: Add temperature to image

Post by Sigge »

ps aux | grep trigger
www-data 9230 0.0 0.2 83380 19392 ? S 00:05 0:08 /usr/bin/perl -wT /usr/bin/zmtrigger.pl
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

Re: Add temperature to image

Post by Sigge »

After reinstall of ZM and attaching a simple webcam.

I have had partial success.

I removed the special character in 22.9°C so that the message became '1|show|0|||22.9 C'. And I switched mode from "monitor" to "modect.

That seemed to work.

But it only works sometimes. As you can see in the log, the exact same trigger works and does not.

Code: Select all

2017-01-18 21:33:39.324610	zmtrigger		4956	INF	Updated show text to '22.9 C'	zmtrigger.pl	
2017-01-18 21:33:31.311293	zma_m1		6541	INF	1: 4000 - Analysing at 9.52 fps	zm_monitor.cpp	1287
2017-01-18 21:33:11.988174	zmc_dvideo0		5973	INF	1: 34000 - Capturing at 10.00 fps	zm_monitor.cpp	3116
2017-01-18 21:31:46.127781	zma_m1		6541	INF	1: 3000 - Analysing at 8.85 fps	zm_monitor.cpp	1287
2017-01-18 21:31:31.532933	zmc_dvideo0		5973	INF	1: 33000 - Capturing at 9.26 fps	zm_monitor.cpp	3116
2017-01-18 21:30:43.139750	zmtrigger		4956	WAR	Can't find monitor '1' for message '1|show|0|||22.9 C'	zmtrigger.pl
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Add temperature to image

Post by rockedge »

Wow I totally forgot to mention the camera mode should be "Nodect"!!! For the trigger to work correctly. The other motion detection modes will work but it is much better in your case to use Nodect. Sorry about that.
From the docs -> https://zoneminder.readthedocs.io/en/st ... nitor.html
Function
This essentially defines what the monitor is doing. This can be one of the following;

None – The monitor is currently disabled. No streams can be viewed or events generated. Nothing is recorded.

Monitor – The monitor is only available for live streaming. No image analysis is done so no alarms or events will be generated, and nothing will be recorded.

Modect – or MOtion DEteCTtion. All captured images will be analysed and events generated with recorded video where motion is detected.

Record – The monitor will be continuously recorded. Events of a fixed-length will be generated regardless of motion, analogous to a conventional time-lapse video recorder. No motion detection takes place in this mode.

Mocord – The monitor will be continuously recorded, with any motion being highlighted within those events.

Nodect – or No DEteCTtion. This is a special mode designed to be used with external triggers. In Nodect no motion detection takes place but events are recorded if external triggers require it.
https://zoneminder.readthedocs.io/en/st ... nents.html
“<id>|<action>|<score>|<cause>|<text>|<showtext>”
where
‘id’ is the id number or name of the ZM monitor.
‘action’ is ‘on’, ‘off’, ‘cancel’ or ‘show’ where ‘on’ forces an alarm condition on, ‘off’ forces an alarm condition off and ‘cancel’ negates the previous ‘on’ or ‘off’. The ‘show’ action merely updates some auxiliary text which can optionally be displayed in the images captured by the monitor. Ordinarily you would use ‘on’ and ‘cancel’, ‘off’ would tend to be used to suppress motion based events. Additionally ‘on’ and ‘off’ can take an additional time offset, e.g. on+20 which automatically ‘cancel’s the previous action after that number of seconds.
‘score’ is the score given to the alarm, usually to indicate it’s importance. For ‘on’ triggers it should be non-zero, otherwise it should be zero.
‘cause’ is a 32 char max string indicating the reason for, or source of the alarm e.g. ‘Relay 1 open’. This is saved in the ‘Cause’ field of the event. Ignored for ‘off’ or ‘cancel’ messages.
‘text’ is a 256 char max additional info field, which is saved in the ‘Description’ field of an event. Ignored for ‘off’ or ‘cancel’ messages.
‘showtext’ is up to 32 characters of text that can be displayed in the timestamp that is added to images. The ‘show’ action is designed to update this text without affecting alarms but the text is updated, if present, for any of the actions. This is designed to allow external input to appear on the images captured, for instance temperature or personnel identity etc.
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

Re: Add temperature to image

Post by Sigge »

Np, seems to be working now! Thanks!

I just added the php script to cron and it seems to be working.
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

Re: Add temperature to image

Post by Sigge »

I am now trying to update more than one monitor.

How do I make trigger stop reading one message and start the next? CR, EoF?

1|show|0|||6.2 C
2|show|0|||6.2 C
3|show|0|||6.2 C

This gives me "6.2 C2" as text update ...
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Add temperature to image

Post by rockedge »

Here is an example PHP script called sendtosock.php that sends a command string to the zmTrigger.pl sock to SHOW in the %Q place holder of a selected monitor's stream view. To send the zmTrigger.pl the SHOW command for multipule monitors you would call this script for each monitor.
http://localhost/sendtosock.php?mon=1
http://localhost/sendtosock.php?mon=2
which would display the temp on monitor 1 and 2.
I think opening a connection to the sock and closing each time worked well for me. Otherwise I think you would have to escape the end of the command using methods that a Telnet connection likes.

Code: Select all

<?php
// the url example : http://localhost/sendtosock.php?mon=1   
// to send and show the temp string in 2 monitors or more, call the script for each monitor individually.
  
   $monitor = $_REQUEST['mon'];     
   
    $temperature_string = system('temper-poll');
    $temperature_string_array = explode(" ",$temperature_string);
   unset($temperature_string_array[0]);
   unset($temperature_string_array[1]);
    $temperature_string_dirty = implode(" ",$temperature_string_array);
    $temperature_string = str_replace(chr(194)," ",$temperature_string_dirty);
    
    $extTriggerx = "$monitor|show|255|||$temperature_string";    

// $cfgServer = "192.168.0.9";

   $cfgServer = "localhost";
   $cfgPort = 6802;

$conn_handle = fsockopen($cfgServer, $cfgPort);
 if(!$conn_handle) {
        echo "Connection failed ";
   exit();
    }else{
      //  echo "Connected <br>";
        fputs($conn_handle, $extTriggerx);
    }  
fclose($conn_handle);
 
?>
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Add temperature to image

Post by knight-of-ni »

What Function did you set monitor 2 to?

UPDATE: oh, nevermind. I responded to an old post, which has already been answered
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

Re: Add temperature to image

Post by Sigge »

Thanks again for pointing me in the right direction.

To insert text to multiple monitos a simple \n will do it.
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

Re: Add temperature to image

Post by Sigge »

I´m getting segmentation fault when trying to use " ▒C ". thats char(194).

Should this be reported as a bug?
Sigge
Posts: 116
Joined: Mon May 02, 2016 8:14 am

Re: Add temperature to image

Post by Sigge »

I am looking through your blog and have ordered all the hardware.

Now, I don´t understand how you use the USB to power your device? Do you convert 5 v to 3,3 in the case or do you send 3,3 over a usb cable?

Thanks
/Sigge
knnniggett wrote:You write a script, which reads the temp from your device, then it should write that data to one of the sockets zmtrigger creates after you enable it. When zmtrigger is started, it creates a network and a unix socket. You send it a simple ascii string, defined in the docs mentioned earlier.

Just google how to write to a socket for the programming/scripting language of your choice if you don't know how to do that. Fairly straight forward.

I was going to just point you to my blog:
http://zmtrigger.blogspot.com/p/display-real.html

But when I went to that page, it was mostly empty. Apparently, I forgot to document the project I did using this feature. It is still in my head.

What I did was wire a DHT22 temp sensor to an esp8266. This chip is basically a mini adruino with builtin wifi.

It sends the temp to my zoneminder server every 15 seconds. Since I never uploaded the sketch to my blog, I pasted it below. You can see what I sent to the zm server socket. If your sensor is on the same machine running zmtrigger, then naturally the server ip becomes localhost. You could just write to the zmtrigger.sock file instead if you want.

Code: Select all

/*
* ESP8266_zmtrigger 
*
* Date of Last Revision: Jan 14, 2015
*
* Upon activation of GPIO2, this sketch sends a user defined command to a ZoneMinder 
* server running zmtrigger on port 6802.
* 
*/

#include <Arduino.h>
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WebServer.h>

#define GPIO0 0
#define GPIO2 2
//DHT22 Sensor
#define DHTTYPE DHT22
#define DHTPIN  2

// ThingSpeak Settings
const char tsserver[]="184.106.153.149";
const String writeapi="thingspeak_api_key_here";
const int updateThingSpeakInterval = 60 * 1000; // 60 second interval at which to update ThingSpeak
const int updateZmTriggerInterval = 15 * 1000; // 15 second interval at which to update zoneminder

// DHT22 Settings
float humidity, temp_f;  // Values read from sensor
const int interval = 2000;              // interval at which to read sensor


ESP8266WiFiMulti WiFiMulti;
WiFiClient client;
ESP8266WebServer server(80);

// Define global variables
const char zmserver[] = "192.168.1.10";
const int port = 6802;
unsigned long previousMillis = 0;
unsigned long lastZMTriggerTime = 0;
unsigned long lastThngSpkTime = 0;
int throttle = 1000; // Don't send more than 1 message per this value in milliseconds
byte netFails = 0;
String TSerrorMsg = "No Thingspeak Error Reported";
String ZMerrorMsg = "No ZoneMinder Error Reported";
String TSsuccessMsg = "No Thingspeak Success Reported";
String ZMsuccessMsg = "No ZoneMinder Success Reported";
const String htmlHead = "<html>\r\n<head>\r\n<meta http-equiv='refresh' content='61'>\r\n</head>\r\n<body>\r\n";
const String htmlTail = "\r\n</body>\r\n</html>\r\n";
byte percentQ = 0;

// Initialize DHT sensor 
// NOTE: For working with a faster than ATmega328p 16 MHz Arduino chip, like an ESP8266,
// you need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold.  It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value.  The default for a 16mhz AVR is a value of 6.  For an
// Arduino Due that runs at 84mhz a value of 30 works.
// This is for the ESP8266 processor on ESP-01 
DHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266

/* 
*  zmTrigger expects commands to be in the following format:
*  
*<id>|<action>|<score>|<cause>|<text>|<showtext>
*
*<id>
*  is the id number or name of the ZM monitor.
*  
*<action>
*  Valid actions are 'on', 'off', 'cancel' or 'show' where
*  'on' forces an alarm condition on;
*  'off' forces an alarm condition off;
*  'cancel' negates the previous 'on' or 'off'.
*  The 'show' action merely updates some auxiliary text which can optionally
*  be displayed in the images captured by the monitor. Ordinarily you would
*  use 'on' and 'cancel', 'off' would tend to be used to suppress motion
*  based events. Additionally 'on' and 'off' can take an additional time
*  offset, e.g. on+20 which automatically 'cancel's the previous action
*  after that number of seconds.
*  
*<score>
*  is the score given to the alarm, usually to indicate it's
*  importance. For 'on' triggers it should be non-zero, otherwise it should
*  be zero.
*  
*<cause>
*  is a 32 char max string indicating the reason for, or source of
*  the alarm e.g. 'Relay 1 open'. This is saved in the 'Cause' field of the
*  event. Ignored for 'off' or 'cancel' messages.
*  
*<text>
*  is a 256 char max additional info field, which is saved in the
*  'Description' field of an event. Ignored for 'off' or 'cancel' messages.
*  
*<showtext>
*  is up to 32 characters of text that can be displayed in the
*  timestamp that is added to images. The 'show' action is designed to
*  update this text without affecting alarms but the text is updated, if
*  present, for any of the actions. This is designed to allow external input
*  to appear on the images captured, for instance temperature or personnel
*  identity etc.
*/

String zmtriggerShowText = "15|show||||";

void handle_root()
{
  String Msg = "Hello from the ESP8266!<br><br>This server responds to the following urls:<br>";
  Msg += "<a href=\"/gpio0\">/gpio0</a><br>";
  Msg += "<a href=\"/gpio2\">/gpio2</a><br>";
  Msg += "<a href=\"/temp\">/temp</a><br>";
  Msg += "<a href=\"/temp_val\">/temp_val</a><br>";
  Msg += "<a href=\"/humidity\">/humidity</a><br>";
  Msg += "<a href=\"/humidity_val\">/humidity_val</a><br>";
  Msg += "<a href=\"/error\">/error</a><br>";
  Msg += "<a href=\"/success\">/success</a><br>";
  Msg += "<a href=\"/status\">/status</a><br>";
  server.send(200, "text/html", htmlHead+Msg+htmlTail);
  delay(100);
}

bool gettemperature() {
  // Wait at least 2 seconds seconds between measurements.
  // if the difference between the current time and last time you read
  // the sensor is bigger than the interval you set, read the sensor
  // Works better than delay for things happening elsewhere also
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis >= interval) {
    // save the last time you read the sensor 
    previousMillis = currentMillis;   

    // Reading temperature for humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
    humidity = dht.readHumidity();          // Read humidity (percent)
    temp_f = dht.readTemperature(true);     // Read temperature as Fahrenheit
  }
  return( isnan(humidity) || isnan(temp_f) );
}

void updateThingSpeak(String tsData) {
  // Create the client object here so it is destroyed after each update attempt
  WiFiClient client;
  
  if (client.connect(tsserver, 80)) {
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + writeapi + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("\n\n");
    client.print(tsData);

    if (client.connected()) { // We got a response from the server but we don't yet know what kind of response

      String Msg = client.readString();
      if ( Msg.substring(0,Msg.indexOf("\r\n")).indexOf(" 200 ") > -1 ) { // Check the message for an http resposne code of 200
        Serial.println();
        Serial.println("HTTP 200 Response received. Data Sent to ThingSpeak!");
        TSsuccessMsg = Msg;
      } else {
        Serial.println();
        Serial.println("ThingSpeak server returned an HTTP error code. Check HTTP://"+String(WiFi.localIP())+"/error for the response message.");
        TSerrorMsg = Msg;
      }     
      netFails = 0;
    } else {
      TSerrorMsg = "Timed out waiting for a response from Thingspeak server!";
      Serial.println();
      Serial.println(TSerrorMsg);
    }
  } else {
    TSerrorMsg = "Connection refused when connecting to Thingspeak!";
    Serial.println();
    Serial.println(TSerrorMsg);
    netFails++;
  }
  //Serial.println(client.readString());
  client.stop();
}

void WiFiStatus() {
    
    if (WiFi.RSSI() <= -100) {
      percentQ = 0;
    } else if (WiFi.RSSI() >= -50) {
      percentQ = 100;
    } else {
      percentQ = 2 * (WiFi.RSSI() + 100);
    }

    Serial.println("");
    Serial.println("WiFi Status");
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
    Serial.print("MAC address: ");
    Serial.println(WiFi.macAddress());
    Serial.print("SSID: ");
    Serial.println(WiFi.SSID());
    Serial.print("Signal Strength (%): ");
    Serial.println(percentQ);
}

void ChipInfo() {
  Serial.println();
  Serial.print("Flash Chip ID: ");
  Serial.println(ESP.getFlashChipId());
  Serial.print("Size of ESP8266 flash chip: ");
  Serial.println(ESP.getFlashChipRealSize());
  Serial.print("Flash Chip Speed: ");
  Serial.println(ESP.getFlashChipSpeed());
  Serial.print("Flash Chip Mode: ");
  Serial.println(ESP.getFlashChipMode());
  Serial.println();
}

void updateZMTrigger(String Cmd) {
  if (client.connect(zmserver, port)) {
    client.println(Cmd);

    if (client.connected()) {
      ZMsuccessMsg = "Zmtrigger ShowText Sent to ZoneMinder";
      Serial.println();
      Serial.println(ZMsuccessMsg);
      Serial.println(Cmd);
      netFails = 0;
    } else {
      ZMerrorMsg = "Timed out connecting to ZoneMinder server";
      Serial.println();
      Serial.println(ZMerrorMsg);
    }
  } else {
    ZMerrorMsg="Connection refused connecting to ZoneMinder server";
    Serial.println();
    Serial.println(ZMerrorMsg);
    netFails++;
  }
}

void setup() {
    // Configure our GPIO's as inputs
    pinMode(GPIO0, INPUT_PULLUP);
    pinMode(GPIO2, INPUT);
    
    Serial.begin(115200);
   // Serial.setDebugOutput(true);

    Serial.println("");

    for(uint8_t t = 4; t > 0; t--) {
        Serial.printf("[SETUP] WAIT %d...\n", t);
        Serial.flush();
        delay(1000);
    }

    WiFiMulti.addAP("ssid1", "password1");
    WiFiMulti.addAP("ssid2", "password2");

    ChipInfo();
    
    // Wait for connection
    Serial.print("Waiting for WiFi to Connect...");
    while (WiFiMulti.run() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("Connected!");
    server.on("/", handle_root);
  
    server.on("/gpio0", [](){  // url to display the current value of GPIO0
      server.send(200, "text/html", htmlHead+"Current value of GPIO0: "+String(digitalRead(GPIO0))+htmlTail);
    });

    server.on("/gpio2", [](){  // url to display the current value of GPIO2
      server.send(200, "text/html", htmlHead+"Current value of GPIO2: "+String(digitalRead(GPIO2))+htmlTail);
    });

    server.on("/temp", [](){  // url to display the temperature with html formatting
      server.send(200, "text/html", htmlHead+"Temperature (deg. F): "+String(temp_f,2)+htmlTail);
    });

    server.on("/temp_val", [](){  // url to display the raw temperature value only
      server.send(200, "text/plain", String(temp_f,2));
    });

    server.on("/humidity", [](){  // url to display the humidity with html formatting
      server.send(200, "text/html", htmlHead+"Humidity (%): "+String(humidity,1)+htmlTail);
    });

    server.on("/humidity_val", [](){  // url to display the raw humidity calue only
      server.send(200, "text/plain", String(humidity,1));
    });
    
    server.on("/error", [](){  // url to display the last reported error message with html formatting
      TSerrorMsg.replace("\r\n","<br>"); // replace new lines with html <br> for readability
      server.send(200, "text/html", htmlHead+"Last reported ZoneMinder error message:<br><br>"+ZMerrorMsg+"<br><br>Last reported ThingSpeak error message:<br><br>"+TSerrorMsg+htmlTail);
    });

    server.on("/success", [](){  // url to display the last reported success message with html formatting
      TSsuccessMsg.replace("\r\n","<br>"); // replace new lines with html <br> for readability
      server.send(200, "text/html", htmlHead+"Last reported ZoneMinder success message:<br><br>"+ZMsuccessMsg+"<br><br>Last reported ThingSpeak success message:<br><br>"+TSsuccessMsg+htmlTail);
    });

    server.on("/status", [](){  // url to display esp8266 status
      server.send(200, "text/html", htmlHead+"IP Address: "+WiFi.localIP()+"<br>"+
                                             "MAC address: "+WiFi.macAddress()+"<br>"+
                                             "SSID: "+WiFi.SSID()+"<br>"+
                                             "Signal Strength (%): "+percentQ+"<br>"+
                                             "Number of Consecutive Network Errors: "+netFails+"<br>"+
                                              htmlTail);
    });

    gettemperature();
    server.begin();
    Serial.println("");
    Serial.println("HTTP server started");
}

void loop() {
  
    server.handleClient();
    
    // Reset previousMillis when millis overflows back to zero
    if ( millis() - previousMillis < 0 ) {
      previousMillis = 0;
    }

    // Reset lastZMTriggerTime when millis overflows back to zero
    if ( millis() - lastZMTriggerTime < 0 ) {
      lastZMTriggerTime = 0;
    }

    // Reset lastThngSpkTime when millis overflows back to zero
    if (millis() - lastThngSpkTime < 0 ) {
      lastThngSpkTime = 0;
    }

    // Update ThingSpeak
    if (millis() - lastThngSpkTime > updateThingSpeakInterval) {
        if (!gettemperature()) {
            updateThingSpeak("field1="+String(temp_f,2)+"&field2="+String(humidity,1)+"&field3="+String(WiFi.RSSI()));
            Serial.println("Temperature (deg. F): "+String(temp_f,2));
            Serial.println("Humidity (%): "+String(humidity,1));
        } else {
            TSerrorMsg="Temperature or Humidity read failed. Skipping Thingspeak update.";
            Serial.println();
            Serial.println(TSerrorMsg);
        }
        lastThngSpkTime = millis();
    }

    // Update zmtrigger
    if (millis() - lastZMTriggerTime > updateZmTriggerInterval) {
        WiFiStatus();
        updateZMTrigger(zmtriggerShowText+" - "+String(temp_f,2)+" Deg. F");
        lastZMTriggerTime = millis();
    }

    if ( netFails >= 15 ) {
      Serial.println("Too many network failures. Restarting WiFi....");
      //delay(3000);
      WiFi.reconnect();
      netFails = 0;
      // ESP.reset();
      delay(3000);
    }

}
User avatar
MJN
Posts: 251
Joined: Wed Jan 17, 2007 10:29 am
Location: Wiltshire, UK

Re: Add temperature to image

Post by MJN »

Baylink wrote:If I'm not mistaken, I have recently seen mention of a camera that has a built in temp sensor, and can OSD the reading for you. I can't tell you which one, alas.
For the sake of the archives, the Wansview K1 is one such camera (also includes humidity) however mine always reads around 1C too high. I got in touch with Wansview and, if my interpretation of what they said is correct, they are aware that there is an issue with accuracy and are seeking a fix.
Locked