04 July, 2024
What rector rules do you use?
Programing Coderfunda
July 04, 2024
No comments
I am using a few, such as the early return rules and moving the property to the constructor as I think they're niceties but I'm interested in what rules the wider community uses.
All the rules seem like such good ideas but I'm not sure if it is wise to use them all, even if the application is pretty well tested. submitted by /u/TertiaryOrbit
[link] [comments]
Unite JavaScript Power with Laravel & Inertia
Programing Coderfunda
July 04, 2024
No comments
03 July, 2024
how can i find message window in Quartus
Programing Coderfunda
July 03, 2024
No comments
I'm using Quartus eda tool for fpga jobs with verilog HDL.
For compiling, i need message window to know errors in my code blocks.
But i can't find message window that indicate errors below the code blocks.
I wanted to extend code blocks so i dragged with my mouse and reduced messages window.
I compiled my code blocks but no messages window appeared.
So, I tried to solve problems in two ways but it didn't worked.
First, I tried rebooting the program.
Next, i clicked the window bar but message window didn't appear.
Thanks for reading. Hopes for good answers.
is there a way to print a bank check from a template where the user only puts the amount and the name?
Programing Coderfunda
July 03, 2024
No comments
Guys i really need help in this, i'm so lost in this i've tried everything
this is the code of the program i did,
import tkinter as tk
from fpdf import FPDF
import num2words
def generate_cheque():
amount = amount_entry.get().replace(" ", "")
amount_parts = amount.split(".")
amount_in_letters = num2words.num2words(int(amount_parts[0]), lang='fr').replace("virgule", "comma").replace("zero", "")
amount_in_letters += " dinars algeriens"
if int(amount_parts[1]) > 0:
amount_in_letters += " et " + num2words.num2words(int(amount_parts[1]), lang='fr').replace("virgule", "comma").replace("zero", "") + " centimes"
location = location_entry.get()
date = date_entry.get()
company_name = company_name_entry.get()
# Convert dimensions from inches to points
width_in_inches = 8.5
height_in_inches = 3.5
width_in_points = width_in_inches * 72
height_in_points = height_in_inches * 72
pdf = FPDF(unit="pt", format=(width_in_points, height_in_points))
pdf.add_page()
pdf.set_font("Arial", size=12)
# Add date
pdf.set_xy(480, 150)
pdf.cell(0, 10, txt=date, align="R")
# Add amount in numbers
pdf.set_xy(450, 50)
pdf.cell(0, 10, txt=amount, align="R")
# add location
pdf.set_xy(400,150)
pdf.cell(0,10, txt=location, align="L")
# Add amount in letters
pdf.set_xy(110,70)
pdf.multi_cell(0, 10, txt=amount_in_letters, align="L")
# Add company name
pdf.set_xy(50, 120)
pdf.cell(0, 10, txt=company_name, align="L")
# Save the PDF
pdf.output("cheque.pdf", "F")
result_label.config(text="Cheque generated successfully!")
root = tk.Tk()
root.title("Cheque Generator")
amount_label = tk.Label(root, text="Amount (000 000 000.00):")
amount_label.pack()
amount_entry = tk.Entry(root)
amount_entry.pack()
location_label = tk.Label(root, text="Location:")
location_label.pack()
location_entry = tk.Entry(root)
location_entry.pack()
date_label = tk.Label(root, text="Date (DD.MM.YYYY):")
date_label.pack()
date_entry = tk.Entry(root)
date_entry.pack()
company_name_label = tk.Label(root, text="Company Name:")
company_name_label.pack()
company_name_entry = tk.Entry(root)
company_name_entry.pack()
generate_button = tk.Button(root, text="Generate Cheque", command=generate_cheque)
generate_button.pack()
result_label = tk.Label(root, text="")
result_label.pack()
root.mainloop()
is there a way to like creates the perfectly aligned pdf check file?
Salt-Stack: Looking for a neet way to enforce a state only if a minon has seLinux installed
Programing Coderfunda
July 03, 2024
No comments
Attempts that have me despairing are:
* there appears to be no state in salt querying whether a given binary is on the $PATH - checking for sestatus is what I was after here.
* salt.states.selinux is not available on systems devoid of seLinux, so it's functionality does not help.
* I could not find any salt functionality to query for the local availability of something like salt.states.selinux (see above) either.
Any hint on how to go about this is appreciated.
Laravel v11.14.0 Released: Improvements server log and support in Stringable class for Markdown extensions - msamgan.com
Programing Coderfunda
July 03, 2024
No comments
https://msamgan.com/laravel-v11140-released-improvements-server-log-and-support-in-stringable-class-for-markdown-extensions submitted by /u/samgan-khan
[link] [comments]
allure reports not running, although allure is installed - allure command not found
Programing Coderfunda
July 03, 2024
No comments
$ allure generate ./allure-results --clean && allure open
bash: allure: command not found
I have allure-report folder and allure-results folder. Results folder holds up to date records, but nothing is being written to report folder.
Package.json looks correct - contains references to allure:
{
"name": "automation-poc",
"version": "2.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/nightwatch --retries 1",
"cleanConfigFiles": "del 'config/*.conf.js'",
"cleanReports": "del 'reports/*'"
},
"author": "Alex",
"license": "ISC",
"dependencies": {
"allure-commandline": "^2.29.0",
"chromedriver": "^94.0.0",
"csvtojson": "^2.0.10",
"del": "^4.1.1",
"del-cli": "^5.0.0",
"nightwatch": "^2.2.3",
"nightwatch-allure": "^1.2.0",
"selenium-server": "^3.141.59",
"uuid": "^10.0.0",
"yargs": "^15.3.1"
}
}
I've run various commands:
npm install allure-commandline
npm install nightwatch-allure
allure generate ./allure-results --clean && allure open
allure --version
npm install -g allure-commandline
npm install -g nightwatch-allure
I've made sure there's an entry in System Variables for the location of \node_modules\allure-commandline\bin
I've tried deleting the node_modules folder and running npm install again
02 July, 2024
How do iI fix the error with UIViewControllerRepresentable?
Programing Coderfunda
July 02, 2024
No comments
import SwiftUI
import AVKit
import UIKit
struct PlayerView: UIViewControllerRepresentable {
typealias UIViewControllerType = AVPlayerViewController
var url: String = "
https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_adv_example_hevc/master.m3u8"
/>
func makeUIViewController(context: Context) -> AVPlayerViewController {
let controller = AVPlayerViewController()
// controller.navigationItem.hidesBackButton = true
// controller.showsPlaybackControls = false
controller.player = AVPlayer(url: URL(string: url)!)
controller.player?.playImmediately(atRate: 1.0)
return controller
}
func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) {
}
class Coordinator: NSObject, AVPlayerViewControllerDelegate {
}
func makeCoordinator() -> Coordinator {
Coordinator()
}
}
a prompt answer.....
Unable to calculate pod specific utilization of the resource through PromQL
Programing Coderfunda
July 02, 2024
No comments
When I am trying to aggregate the data based on pod to namespace level it is not matching the data directly driven by namespace filter.
I want the pod specific data which matches the namespace data when got aggregated.
For namespace specific data I am using below four queries. (Which is giving me correct answer)
{"cpu_usage": f"sum_over_time(namespace:container_cpu_usage:sum{{namespace='{namespace}'}}[1d])",
"cpu_request":f"sum_over_time(namespace_cpu:kube_pod_container_resource_requests:sum{{namespace='{namespace}'}}[1d])",
"memory_usage":f"sum_over_time(namespace:container_memory_usage_bytes:sum{{namespace='{namespace}'}}[1d])",
"memory_request":f"sum_over_time(namespace_memory:kube_pod_container_resource_requests:sum{{namespace='{namespace}'}}[1d])"}
For pod specific data I am using below four queries. (When I aggregate this queries using sum (query) by (namespace) the result is not matching the above queries' readings.)
{"cpu_usage": f"sum_over_time(pod:container_cpu_usage:sum{{namespace='{namespace}'}}[1d])",
"cpu_request": f"sum_over_time(kube_pod_container_resource_requests{{namespace='{namespace}', resource = 'cpu'}}[1d])",
"memory_usage":f"sum(sum_over_time(container_memory_usage_bytes{{namespace='{namespace}', container!='POD', container!=''}}[1d])) by (pod)",
"memory_request": f"sum_over_time(kube_pod_container_resource_requests{{namespace='{namespace}', resource = 'memory'}}[1d])"}
tl;dr
I want the same data as I am getting for the whole namespace but I want to segregate the usage and request for the specific pods.
Amazon athena, presto sql :INVALID_FUNCTION_ARGUMENT: Cannot unnest type: varchar
Programing Coderfunda
July 02, 2024
No comments
record_id labels
001 ['first_record','transfer']
002 ['withdraw', 'holiday']
003 ['direct','change_password','transfer']
004 ['change_password']
......
Labels column is of string type.
Tried to unnest labels column
select record_id, new_labels from transactions, UNNEST(labels ) as t(new_labels ) order by record_id, new_labels
but got following error
INVALID_FUNCTION_ARGUMENT: Cannot unnest type: varchar
Then tried to cast string to array then to the unnest
select record_id, cast(json_parse(labels) as array(varchar)) as labels from transactions
but got following error:
INVALID_CAST_ARGUMENT: Cannot cast to array(varchar). ['withdraw', 'holiday']
Then simply tried
select cast(['first_record','transfer']) as array(varchar)
it returned
mismatched input '['. Expecting:
Multiply Collections, Number Pairs & Markdown Extensions
Programing Coderfunda
July 02, 2024
No comments
Laravel sending contact form getting 550 error
Programing Coderfunda
July 02, 2024
No comments
"Expected response code "250" but got code "550", with message "550-Sorry! This server is unable to send email from this domain: 550 gmail.com. Please try sending from a domain on this server."
MAIL_DRIVER=smtp
MAIL_HOST=mail.domain.com
MAIL_PORT=465
MAIL_USERNAME=me@domain.com
MAIL_PASSWORD=......
MAIL_ENCRYPTION=ssl
Controller:
Namespace App\Http\Controllers;
use App\Notifications\ContactFormMessage;
use App\Http\Controllers\Controller;
use App\Http\Requests\ContactFormRequest;
use App\Recipient;
Class ContactController extends Controller
{
public function show()
{
return view('contact.index');
}
public function mailContactForm(ContactFormRequest $message, Recipient $recipient)
{
$recipient->notify(new ContactFormMessage($message));
return redirect()->back()->with('message', 'Thanks for your message! We will get back to you soon!');
}
}
Model recipient
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Model;
class Recipient extends Model
{
use Notifiable;
protected $recipient;
protected $email;
public function __construct() {
$this->recipient = config('recipient.name');
$this->email = config('recipient.email');
}
}
Checked email settings and password. ran composer dump-autoload
01 July, 2024
Packing, unpacking and storing parameter pack in a tuple in c++ 17
Programing Coderfunda
July 01, 2024
No comments
I've seen parts of this answered however I'm unsure how a complete solution would look like, I apologize, but I don't really understand parameter packs, and how they relate to tuple.
Here's bits of my code that I'm trying to make work together:
I have this which is basically just calling the function, I think this can be used to save the call into the "callable" structure, to make an interface.
from this question:
C++ generic function call with varargs parameter
template
auto call(R(*function)(Args...), Args... args) -> typename std::enable_if::value, R>::type {
return function(args...);
}
template
void call(void (*function)(Args...), Args... args) {
function(args...);
}
And this structure which should store the parameters and the function pointer. (thanks to RaymondChen for pointing out how it should be correctly)
template
struct callable
{
R(*function)(Args...);
std::tuple params;
callable(Args... argv):
params(std::make_tuple(argv...))
{}
};
I'm still unsure how I would actually call back the function with the tuple, as far as I understand I should somehow turn the tuple back to Args... and then simply call it.
What I'm trying to achieve:
* Save a call to be used later on
* Create my own call and fill it with my own parameters, from a running app.
* Read out saved parameters to do some manner of debugging.
Replace a record with a value zero when a specific number is not find with shellscript
Programing Coderfunda
July 01, 2024
No comments
Input file example:
2022-11-17 05:00:02.327, MSG:86442, AppID:22
2022-11-17 05:00:10.829, MSG:81874, AppID:9
2022-11-17 05:00:14.143, MSG:81778, AppID:10
2022-11-17 05:00:16.365, MSG:81782, AppID:22
2022-11-17 05:00:25.010, MSG:82959, AppID:22
2022-11-17 05:00:30.647, MSG:58653, AppID:22
2022-11-17 05:00:40.852, MSG:58198, AppID:11
2022-11-17 05:00:45.104, MSG:89039, AppID:22
2022-11-17 05:00:45.221, MSG:83564, AppID:21
2022-11-17 05:01:00.618, MSG:34115, AppID:20
2022-11-17 05:01:02.692, MSG:86963, AppID:21
2022-11-17 05:01:02.927, MSG:81387, AppID:10
2022-11-17 05:01:04.826, MSG:82119, AppID:11
2022-11-17 05:01:04.926, MSG:82111, AppID:11
2022-11-17 05:01:04.945, MSG:82116, AppID:13
2022-11-17 05:01:00.618, MSG:59110, AppID:20
Output:
# awk -F ',' '{print $2}' test.log|cut -c 10-10|sort|uniq -c
1 0
1 1
2 2
2 3
2 4
1 5
1 6
1 7
2 8
3 9
I try as shown below, but I need to put zero to field where I don't have any records found in $2 at the end with 0 to 9:
2022-11-17 05:00:02.327, MSG:86442, AppID:22
2022-11-17 05:00:14.143, MSG:81778, AppID:10
2022-11-17 05:00:16.365, MSG:81782, AppID:22
2022-11-17 05:00:25.010, MSG:82959, AppID:22
2022-11-17 05:00:40.852, MSG:58198, AppID:11
2022-11-17 05:00:45.104, MSG:89039, AppID:22
2022-11-17 05:01:00.618, MSG:34115, AppID:20
2022-11-17 05:01:02.927, MSG:81387, AppID:10
2022-11-17 05:01:04.826, MSG:82119, AppID:11
2022-11-17 05:01:04.926, MSG:82111, AppID:11
2022-11-17 05:01:04.945, MSG:82116, AppID:13
2022-11-17 05:01:00.618, MSG:59110, AppID:20
Output expectation :
awk -F ',' '{print $2}' test.log|cut -c 10-10|sort|uniq -c
nuberofrecords N° from0 to 9
# awk -F ',' '{print $2}' test.log|cut -c 10-10|sort|uniq -c
nuberofrecords N°from0 to 9
1 0
1 1
2 2
**0 3**
**0 4**
1 5
1 6
1 7
2 8
3 9
get-service needs local account - how to consolidate report
Programing Coderfunda
July 01, 2024
No comments
$computers =
@"
computer1
computer2
"@ -split [Environment]::NewLine
$computers | ForEach-Object {
$ServerUserId = "_$\user1"
$ServerPassword = ConvertTo-SecureString -String 'complexpassword' -AsPlainText -Force
$Credential = New-Object -TypeName PSCredential -ArgumentList $ServerUserId, $ServerPassword
Enter-PSSession -ComputerName $_ -Credential $Credential
"Computer name: $_"
get-service -ComputerName $computers -Name `
Service* `
Exit-PSSession
}
Output:
Computer name: Computer1
Service A
Service B
Computer name: Computer2
Service Y
Service Z
Would like it to look like:
Service A Computer1
Service B Computer1
Service Y Computer2
Service Z Computer2
Adding Real Time Chat to Laravel Using Reverb & Vue
Programing Coderfunda
July 01, 2024
No comments
Laravel, the web artisan's favorite PHP framework, has just got a whole new powerful tool in its arsenal: Reverb. Among the official packages of Laravel, this WebSocket server application would seamlessly let you integrate real-time features in your Laravel-based applications, thereby taking interaction to a whole new level.
What is Laravel Reverb?
Reverb acts as a mediator between your Laravel-based application and its users. It establishes two-way, real-time communication based on WebSockets technology that allows web pages to receive updates on the server without a complete page refresh. This means that your users experience your application more dynamically and responsively.
Key Features of Laravel Reverb
Blazing Speed: Provides outstanding performance for real-time information with no lags.
Scalability: Grow with your applications to handle increased user traffic.
Seamless Integration: It works with broadcasting features added to Laravel and Laravel Echo to make development simple.
Push Updates: Push updates, messages, or events to clients to share your information instantly.
Built-in Security: Data encryption and authentication assurance for security communication
Adding Laravel Reverb to Your Chat Project
With Laravel Reverb, you can build dynamic chat applications. The messages are posted instantly, making users involved comprehensively. Here's a breakdown of the steps involved:
Step 1: Setting Up Your Laravel Project:
*
Ensure you have a Laravel application set up (version 11 or above is recommended).
*
If you're starting fresh, use composer create-project laravel/laravel your-chat-app-name.
Step 2: Install and Configure Reverb:
Install Laravel Reverb by running the following command:
php artisan install:broadcasting
Once you’ve installed Reverb, you can now modify its configuration from the config/reverb.php file. To establish a connection to Reverb, a set of Reverb “application” credentials must be exchanged between the client and server. These credentials are configured on the server and are used to verify the request from the client. You can define these credentials using the following environment variables:
BROADCAST_DRIVER=reverb
REVERB_APP_ID=my-app-id
REVERB_APP_KEY=my-app-key
REVERB_APP_SECRET=my-app-secret
It also automatically creates echo.js in the resources/js directory.
import Echo from 'laravel-echo';
import Pusher from 'pusher-js';
window.Pusher = Pusher;
window.Echo = new Echo({
broadcaster: 'reverb',
key: import.meta.env.VITE_REVERB_APP_KEY,
wsHost: import.meta.env.VITE_REVERB_HOST,
wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
enabledTransports: ['ws', 'wss'],
});
Follow the Laravel documentation for configuration steps specific to your application server
https://laravel.com/docs/11.x/reverb
/>
Step 3: Running a Server
You can launch the Reverb server by using the reverb:start Artisan command:
php artisan reverb:start
By default, the Reverb server will be started at 0.0.0.0:8080, which makes it accessible from all network interfaces.
If you want to set a specific host or port, you can use the –host and –port options when starting the server.
php artisan reverb:start --host=127.0.0.1 --port=9000
You can also define REVERB_SERVER_HOST and REVERB_SERVER_PORT environment variables in your application’s .env configuration file.
Step 4: Setup Database
Open your .env file and adjust the settings to set up your database. Here’s an example using SQLite for simplicity:
DB_CONNECTION=sqlite
DB_DATABASE=/path/to/database.sqlite
You can create an SQLite database by simply running:
touch /path/to/database.sqlite
For this demo, we’ll create five predefined rooms. Let’s start by generating a model ChatMessage with migration for a chat_messages table.
php artisan make:model ChatMessage --migration
To make it simpler, only create name attributes for this model and migrate it.
Schema::create('chat_messages', function (Blueprint $table) {
$table->id();
$table->foreignId('receiver_id');
$table->foreignId('sender_id');
$table->text('text');
$table->timestamps();
});
php artisan migrate
Now, let's add the necessary relationships in the ChatMessage model. Open the ChatMessage.php file in the app/Models directory and update it as follows:
30 June, 2024
Jquery passing data attributes to modal on click link
Programing Coderfunda
June 30, 2024
No comments
The HTML snippet is as following:
Action
*
Contact
The modal snippet is as following :
I seem to be unable to set "modal-title" with the value of attribute "data-userName".
The jquery I thought would do so (only inserted alert to see if value is passed or not) :
$('#modal_contact').on('click', function() {
var $el = $(this);
var $username = $el.data('userName');
alert(username);
});
But it does not seem to work. What would be the proper approach to this ?
Weekly /r/Laravel Help Thread
Programing Coderfunda
June 30, 2024
No comments
* What steps have you taken so far?
* What have you tried from the documentation?
* Did you provide any error messages you are getting?
* Are you able to provide instructions to replicate the issue?
* Did you provide a code example?
* Please don't post a screenshot of your code. Use the code block in the Reddit text editor and ensure it's formatted correctly.
For more immediate support, you can ask in the official Laravel Discord.
Thanks and welcome to the /r/Laravel community! submitted by /u/AutoModerator
[link] [comments]
Is there a __builtin_constant_p() for Visual C++?
Programing Coderfunda
June 30, 2024
No comments
In the answer here (How to have "constexpr and runtime" alias) is a nice use case of it.
EDIT:
My idea was instead of writing something like:
#include
int foo() {
return strlen("text");
}
I could write:
#include
// template_strlen() would be a function that gets the length of a compile-time const string via templates
#define STRLEN(a) (__builtin_constant_p(a) ? template_strlen(a) : strlen(a))
int foo() {
return STRLEN("text");
}
(I guess that is about what was written in the linked question.)
All I need for that is a variant of __builtin_constant_p().
Updating matplotlib graph using tkinter
Programing Coderfunda
June 30, 2024
No comments
So my questions are:
* Is it possible to avoid this problem?
* If it is not possible, what are the alternatives? maybe creating another tkinter window only for the graph?.
Is Laravel Reverb ready for production use?
Programing Coderfunda
June 30, 2024
No comments
29 June, 2024
Combine information in multiple columns into one column on different sheet
Programing Coderfunda
June 29, 2024
No comments
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet1 = ss.getSheetByName('Form Response Data')
const sheet2 = ss.getSheetByName('Data Overview');
let [vb] = sheet1.getDataRange().getDisplayValues().map(([a,b,c,d,e,f,au,az,ba,bb,bc,bd,be])=>
[`${az} ${ba} ${bb} ${bc}`]);
sheet2.getRange(3,10,vb.length,vb[0].length).setValues(vb);
Mastering the Service-Repository Pattern in Laravel
Programing Coderfunda
June 29, 2024
No comments
ESP-32 With DHT-11 Sensor not returning expected output
Programing Coderfunda
June 29, 2024
No comments
Here are the codes:
EXAMPLE CODE that works with my sensor on an ESP-32:
`
#include
/* Uncomment according to your sensortype. */
#define DHT_SENSOR_TYPE DHT_TYPE_11
//#define DHT_SENSOR_TYPE DHT_TYPE_21
//#define DHT_SENSOR_TYPE DHT_TYPE_22
static const int DHT_SENSOR_PIN = 27;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );
/*
* Initialize the serial port.
*/
void setup( )
{
Serial.begin( 9600);
}
/*
* Poll for a measurement, keeping the state machine alive. Returns
* true if a measurement is available.
*/
static bool measure_environment( float *temperature, float *humidity )
{
static unsigned long measurement_timestamp = millis( );
/* Measure once every four seconds. */
if( millis( ) - measurement_timestamp > 3000ul )
{
if( dht_sensor.measure( temperature, humidity ) == true )
{
measurement_timestamp = millis( );
return( true );
}
}
return( false );
}
/*
* Main program loop.
*/
void loop( )
{
float temperature;
float humidity;
/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */
if( measure_environment( &temperature, &humidity ) == true )
{
Serial.print( "T = " );
Serial.print( temperature, 1 );
Serial.print( " deg. C, H = " );
Serial.print( humidity, 1 );
Serial.println( "%" );
}
}
`
---
Here are my results by executing this code:
12:34:16.068 -> T = 26.0 deg. C, H = 6.0%
12:34:19.331 -> T = 26.0 deg. C, H = 6.0%
12:34:22.634 -> T = 27.0 deg. C, H = 6.0%
12:34:25.905 -> T = 27.0 deg. C, H = 6.0%
12:34:29.180 -> T = 27.0 deg. C, H = 6.0%
12:34:32.451 -> T = 27.0 deg. C, H = 6.0%
12:34:35.722 -> T = 28.0 deg. C, H = 7.0%
12:34:38.991 -> T = 28.0 deg. C, H = 7.0%
12:34:42.262 -> T = 28.0 deg. C, H = 7.0%
12:34:45.559 -> T = 28.0 deg. C, H = 7.0%
12:34:48.825 -> T = 29.0 deg. C, H = 8.0%
12:34:52.090 -> T = 29.0 deg. C, H = 8.0%
12:34:55.392 -> T = 30.0 deg. C, H = 8.0%
12:34:58.660 -> T = 31.0 deg. C, H = 9.0%
12:35:01.924 -> T = 31.0 deg. C, H = 9.0%
12:35:05.197 -> T = 31.0 deg. C, H = 9.0%
12:35:08.466 -> T = 32.0 deg. C, H = 9.0%
MY CODE THAT DOES NOT GIVE ANY RESULTS FROM THE DHT11 SENSOR:
`
// Import required libraries
#include
#include "ESPAsyncWebServer.h"
#include
// Replace with your network credentials
const char* ssid = "SSID";
const char* password = "PASSSWORD";
#define DHTPIN 27 // Digital pin connected to the DHT sensor
// Uncomment the type of sensor in use:
#define DHTTYPE DHT_TYPE_11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT_nonblocking dht(DHTPIN, DHTTYPE);
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
static bool measure_environment( float *temperature, float *humidity )
{
static unsigned long measurement_timestamp = millis( );
/* Measure once every four seconds. */
if( millis( ) - measurement_timestamp > 3000ul )
{
if( dht.measure( temperature, humidity ) == true )
{
measurement_timestamp = millis( );
return( true );
}
}
return( false );
}
float temperature;
float humidity;
String readDHTTemperature() {
if( measure_environment( &temperature, &humidity ) == true )
{
Serial.print( "T = " );
Serial.print( temperature, 1 );
Serial.print( " deg. C");
return String(temperature);
}}
String readDHTHumidity() {
if( measure_environment( &temperature, &humidity ) == true )
{
Serial.print( "H = " );
Serial.print( humidity, 1 );
Serial.println( "%" );
return String(humidity);
}}
const char index_html[] PROGMEM = R"rawliteral(
html {
font-family: Arial;
display: inline-block;
margin: 0px auto;
text-align: center;
}
h2 { font-size: 3.0rem; }
p { font-size: 3.0rem; }
.units { font-size: 1.2rem; }
.dht-labels{
font-size: 1.5rem;
vertical-align:middle;
padding-bottom: 15px;
}
ESP32 DHT Server
Temperature
%TEMPERATURE%
°C
Humidity
%HUMIDITY%
%
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperature").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/temperature", true);
xhttp.send();
}, 10000 ) ;
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("humidity").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/humidity", true);
xhttp.send();
}, 10000 ) ;
)rawliteral";
// Replaces placeholder with DHT values
String processor(const String& var){
//Serial.println(var);
if(var == "TEMPERATURE"){
return readDHTTemperature();
}
else if(var == "HUMIDITY"){
return readDHTHumidity();
}
return String();
}
void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
// dht.begin();
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html, processor);
});
server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readDHTTemperature().c_str());
});
server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readDHTHumidity().c_str());
});
// Start server
server.begin();
}
void loop(){
}
`
Here are my results by running this code:
12:27:40.469 -> Connecting to WiFi..
12:27:40.469 -> 10.0.0.236
12:27:47.375 -> T = 0.0 deg. CH = 0.0%
12:28:32.344 -> T = 0.0 deg. CH = 0.0%
12:29:32.312 -> T = 0.0 deg. CH = 0.0%
12:30:32.378 -> T = 0.0 deg. CH = 0.0%
Why is this happening?
The wiring, baud rate of the Serial Monitor is right, and I have tried everything from this website:
https://randomnerdtutorials.com/solved-dht11-dht22-failed-to-read-from-dht-sensor/, but the output keeps saying the temperature and the humidity are 0 or null. How can I change the code which creates a web server to give the right results? Thanks!
(Sorry for any bad grammar or formatting. Let me know if you need any more details. Thanks again!)
Simple concat two array of objects problem
Programing Coderfunda
June 29, 2024
No comments
alert("2.1 after CONCAT plan_cookie = " + JSON.stringify(plan_cookie));
/*
2.1 after CONCAT plan_cookie =
"[{"id":1,"productId":1,"planDescription":"No Protection Plan","originalPrice":0,"salePrice":0,"active":1},
{"id":2,"productId":1,"planDescription":"1 Year Extension Protection Plan","originalPrice":69.99,"salePrice":69.99,"active":1},
{"id":3,"productId":1,"planDescription":"2 Year Extension Protection Plan","originalPrice":89.99,"salePrice":89.99,"active":1},
{"id":4,"productId":1,"planDescription":"3 Year Extension Protection Plan","originalPrice":109.99,"salePrice":109.99,"active":1},
{"id":5,"productId":1,"planDescription":"4 Year Extension Protection Plan","originalPrice":129.99,"salePrice":129.99,"active":1}]
[{"id":6,"productId":3,"planDescription":"No Protection Plan","originalPrice":0,"salePrice":0,"active":1},
{"id":7,"productId":3,"planDescription":"1 Year Extension Protection Plan","originalPrice":79.99,"salePrice":79.99,"active":1},
{"id":8,"productId":3,"planDescription":"2 Year Extension Protection Plan","originalPrice":99.99,"salePrice":99.99,"active":1}]"
*/
Call trace in java
Programing Coderfunda
June 29, 2024
No comments
08 June, 2024
will the jobs need to be reconfigured after we update any Plugins in Jenkins?
Programing Coderfunda
June 08, 2024
No comments




