Sorry for the delayed response, so what I did was i used the puck as a beacon, and added a JavaScript code with NDEFreading event, so basically when someone scans a puck device it should display the current date and time of the sacn, which unfortunately did not work, I read on googlechome that NDEFreading is not supported anymore and it’s a experimental feature, I tried turning on the experimental feature in chrome still did not work.
This is the js code
<script src="https://www.puck-js.com/puck.js"></script>
<script>
// Add an event listener to detect NFC tag scanning
window.addEventListener('NDEFReading', event => {
// Get the data from the NFC tag
const message = event.message;
// Capture current date and time in UK format
const currentTime = new Date();
const day = currentTime.getDate();
const month = currentTime.getMonth() + 1;
const year = currentTime.getFullYear();
const hours = currentTime.getHours();
const minutes = currentTime.getMinutes();
const formattedDate = padNumber(day) + '/' + padNumber(month) + '/' + year;
const formattedTime = padNumber(hours) + ':' + padNumber(minutes);
const checkedInInfo = "Student checked-in at: " + formattedDate + " " + formattedTime;
// Display the NFC data on the webpage
document.getElementById('nfcData').innerText = checkedInInfo;
// Save the NFC data to the logintime textarea
document.getElementById('logintime').value = checkedInInfo;
});
function padNumber(number) {
return (number < 10 ? '0' : '') + number;
}
</script>
Since this did not work, what I have done now is I put the url of my webpage on puck, when scanned it takes user to webpage, they login and on details page they click on checkin button which records date and time.
I want to record the time and date on the event of nfc scan automatically, is this still possible?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hello @Gordon
Sorry for the delayed response, so what I did was i used the puck as a beacon, and added a JavaScript code with NDEFreading event, so basically when someone scans a puck device it should display the current date and time of the sacn, which unfortunately did not work, I read on googlechome that NDEFreading is not supported anymore and it’s a experimental feature, I tried turning on the experimental feature in chrome still did not work.
This is the js code
Since this did not work, what I have done now is I put the url of my webpage on puck, when scanned it takes user to webpage, they login and on details page they click on checkin button which records date and time.
I want to record the time and date on the event of nfc scan automatically, is this still possible?
Can the puck be used just a a beacon?