darfk.net - Thomas Payne - Parking Barcode Generator

Parking Barcode Generator

My local supermarket chain offers the following deal. Free, 90-minute parking in the shopping mall parking lot when you spend $30 or more with them.

The method in which they validate this is via a barcode printed on the receipt which you must scan at the parking fee payment machine. The barcode is the same for each customer but changes every day.

The barcode content is very simple, it's a CODE-128 of 88YYMMDD, where the YYMMDD represents tomorrow's date. For example, the code 88231115 would work for Tuesday 14th November, 2023.

23 November 2023

~~I used to have this generated using Node-RED and have it sent via a Telegram bot.~~

03 October 2025

~~I now just generate the code within the browser, it's a single static HTML file plus a JavaScript library~~

I have now switched to rendering the barcode with rust.

The result can be viewed here

The code to generate the barcode response is as follows:

pub(crate) fn barcode() -> Result<Option<ResponseBox>, AppError> {
    let tz = chrono::FixedOffset::east_opt(60 * 60 * 10).ok_or(AppError::BarcodeDate)?;
    
    let sydney_tomorrow = Utc::now()
        .with_timezone(&tz)
        .checked_add_days(Days::new(1))
        .ok_or(AppError::BarcodeDate)?;
    let date_string = sydney_tomorrow.format("%y%m%d");
    
    let code_string = format!("Ć88{}", date_string);

    let barcode = Code128::new(code_string.as_str())?;
    let encoded = barcode.encode();

    let content = SVG::new(320)
        .xmlns("http://www.w3.org/2000/svg".to_string())
        .generate(encoded)?;

    let cursor = Cursor::new(content);

    Ok(Some(ResponseBox::new(
        StatusCode(200),
        vec![Header::from_str("Content-Type: image/svg+xml").unwrap()],
        Box::new(cursor),
        None,
        None,
    )))
}