Numbering equation for each custom section

I have created an environment named hwp with custom headers and footers that works otherwise very much like the native section environment, in which I can set equations, add figures, etc. What I would like to do is to use the \numberwithin{equation}{section} for hwp. In other words, the numbering of equations should be reset whenever a new hwp is created.

As it appears that I have to work around the \numberwithin command, I have been working on setting up my own counter that would serve the purpose, yet to no avail. The following is the code related to my goal. Any advice would be much appreciated.

\newcounter{hwpcounter}
\newcounter{eqcounter}

\newenvironment{hwp}[1][Prob \arabic{hwpcounter}]
{
\stepcounter{hwpcounter}
\renewcommand{\theequation}{\arabic{hwpcounter}.\theeqcounter}
}

-
Welcome to TeX.SX!](meta.tex.stackexchange.com/q/1436) You don't have to sign with your name since it automatically appears in the lower right corner of your post. –  Jubobs Feb 4 at 16:01

I provided a dummy definition for the hwp environment, since the one given in the question is not complete:

\documentclass{article}
\usepackage{amsmath}

\newcounter{hwpcounter}

\newenvironment{hwp}[1][Prob~\arabic{hwpcounter}]
{\refstepcounter{hwpcounter}\par#1\par\nobreak}
{\par}

\numberwithin{equation}{hwpcounter}

\begin{document}

\begin{hwp}
test
$$a=b.$$
$$a=b.$$
\end{hwp}

\begin{hwp}
test
$$a=b.$$
$$a=b.$$
\end{hwp}

\end{document}


-
Thank you, Gonzalo! This worked like a charm. –  mgu Feb 4 at 16:15